falcon.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 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 <linux/i2c.h>
  16. #include <linux/mii.h>
  17. #include <linux/slab.h>
  18. #include "net_driver.h"
  19. #include "bitfield.h"
  20. #include "efx.h"
  21. #include "mac.h"
  22. #include "spi.h"
  23. #include "nic.h"
  24. #include "regs.h"
  25. #include "io.h"
  26. #include "phy.h"
  27. #include "workarounds.h"
  28. /* Hardware control for SFC4000 (aka Falcon). */
  29. static const unsigned int
  30. /* "Large" EEPROM device: Atmel AT25640 or similar
  31. * 8 KB, 16-bit address, 32 B write block */
  32. large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN)
  33. | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  34. | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)),
  35. /* Default flash device: Atmel AT25F1024
  36. * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */
  37. default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN)
  38. | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  39. | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN)
  40. | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN)
  41. | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN));
  42. /**************************************************************************
  43. *
  44. * I2C bus - this is a bit-bashing interface using GPIO pins
  45. * Note that it uses the output enables to tristate the outputs
  46. * SDA is the data pin and SCL is the clock
  47. *
  48. **************************************************************************
  49. */
  50. static void falcon_setsda(void *data, int state)
  51. {
  52. struct efx_nic *efx = (struct efx_nic *)data;
  53. efx_oword_t reg;
  54. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  55. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state);
  56. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  57. }
  58. static void falcon_setscl(void *data, int state)
  59. {
  60. struct efx_nic *efx = (struct efx_nic *)data;
  61. efx_oword_t reg;
  62. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  63. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state);
  64. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  65. }
  66. static int falcon_getsda(void *data)
  67. {
  68. struct efx_nic *efx = (struct efx_nic *)data;
  69. efx_oword_t reg;
  70. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  71. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN);
  72. }
  73. static int falcon_getscl(void *data)
  74. {
  75. struct efx_nic *efx = (struct efx_nic *)data;
  76. efx_oword_t reg;
  77. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  78. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN);
  79. }
  80. static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
  81. .setsda = falcon_setsda,
  82. .setscl = falcon_setscl,
  83. .getsda = falcon_getsda,
  84. .getscl = falcon_getscl,
  85. .udelay = 5,
  86. /* Wait up to 50 ms for slave to let us pull SCL high */
  87. .timeout = DIV_ROUND_UP(HZ, 20),
  88. };
  89. static void falcon_push_irq_moderation(struct efx_channel *channel)
  90. {
  91. efx_dword_t timer_cmd;
  92. struct efx_nic *efx = channel->efx;
  93. BUILD_BUG_ON(EFX_IRQ_MOD_MAX > (1 << FRF_AB_TC_TIMER_VAL_WIDTH));
  94. /* Set timer register */
  95. if (channel->irq_moderation) {
  96. EFX_POPULATE_DWORD_2(timer_cmd,
  97. FRF_AB_TC_TIMER_MODE,
  98. FFE_BB_TIMER_MODE_INT_HLDOFF,
  99. FRF_AB_TC_TIMER_VAL,
  100. channel->irq_moderation - 1);
  101. } else {
  102. EFX_POPULATE_DWORD_2(timer_cmd,
  103. FRF_AB_TC_TIMER_MODE,
  104. FFE_BB_TIMER_MODE_DIS,
  105. FRF_AB_TC_TIMER_VAL, 0);
  106. }
  107. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  108. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  109. channel->channel);
  110. }
  111. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx);
  112. static void falcon_prepare_flush(struct efx_nic *efx)
  113. {
  114. falcon_deconfigure_mac_wrapper(efx);
  115. /* Wait for the tx and rx fifo's to get to the next packet boundary
  116. * (~1ms without back-pressure), then to drain the remainder of the
  117. * fifo's at data path speeds (negligible), with a healthy margin. */
  118. msleep(10);
  119. }
  120. /* Acknowledge a legacy interrupt from Falcon
  121. *
  122. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  123. *
  124. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  125. * BIU. Interrupt acknowledge is read sensitive so must write instead
  126. * (then read to ensure the BIU collector is flushed)
  127. *
  128. * NB most hardware supports MSI interrupts
  129. */
  130. inline void falcon_irq_ack_a1(struct efx_nic *efx)
  131. {
  132. efx_dword_t reg;
  133. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  134. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  135. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  136. }
  137. irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  138. {
  139. struct efx_nic *efx = dev_id;
  140. efx_oword_t *int_ker = efx->irq_status.addr;
  141. int syserr;
  142. int queues;
  143. /* Check to see if this is our interrupt. If it isn't, we
  144. * exit without having touched the hardware.
  145. */
  146. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  147. netif_vdbg(efx, intr, efx->net_dev,
  148. "IRQ %d on CPU %d not for me\n", irq,
  149. raw_smp_processor_id());
  150. return IRQ_NONE;
  151. }
  152. efx->last_irq_cpu = raw_smp_processor_id();
  153. netif_vdbg(efx, intr, efx->net_dev,
  154. "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  155. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  156. /* Determine interrupting queues, clear interrupt status
  157. * register and acknowledge the device interrupt.
  158. */
  159. BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS);
  160. queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q);
  161. /* Check to see if we have a serious error condition */
  162. if (queues & (1U << efx->fatal_irq_level)) {
  163. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  164. if (unlikely(syserr))
  165. return efx_nic_fatal_interrupt(efx);
  166. }
  167. EFX_ZERO_OWORD(*int_ker);
  168. wmb(); /* Ensure the vector is cleared before interrupt ack */
  169. falcon_irq_ack_a1(efx);
  170. if (queues & 1)
  171. efx_schedule_channel(efx_get_channel(efx, 0));
  172. if (queues & 2)
  173. efx_schedule_channel(efx_get_channel(efx, 1));
  174. return IRQ_HANDLED;
  175. }
  176. /**************************************************************************
  177. *
  178. * EEPROM/flash
  179. *
  180. **************************************************************************
  181. */
  182. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  183. static int falcon_spi_poll(struct efx_nic *efx)
  184. {
  185. efx_oword_t reg;
  186. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  187. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  188. }
  189. /* Wait for SPI command completion */
  190. static int falcon_spi_wait(struct efx_nic *efx)
  191. {
  192. /* Most commands will finish quickly, so we start polling at
  193. * very short intervals. Sometimes the command may have to
  194. * wait for VPD or expansion ROM access outside of our
  195. * control, so we allow up to 100 ms. */
  196. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  197. int i;
  198. for (i = 0; i < 10; i++) {
  199. if (!falcon_spi_poll(efx))
  200. return 0;
  201. udelay(10);
  202. }
  203. for (;;) {
  204. if (!falcon_spi_poll(efx))
  205. return 0;
  206. if (time_after_eq(jiffies, timeout)) {
  207. netif_err(efx, hw, efx->net_dev,
  208. "timed out waiting for SPI\n");
  209. return -ETIMEDOUT;
  210. }
  211. schedule_timeout_uninterruptible(1);
  212. }
  213. }
  214. int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi,
  215. unsigned int command, int address,
  216. const void *in, void *out, size_t len)
  217. {
  218. bool addressed = (address >= 0);
  219. bool reading = (out != NULL);
  220. efx_oword_t reg;
  221. int rc;
  222. /* Input validation */
  223. if (len > FALCON_SPI_MAX_LEN)
  224. return -EINVAL;
  225. /* Check that previous command is not still running */
  226. rc = falcon_spi_poll(efx);
  227. if (rc)
  228. return rc;
  229. /* Program address register, if we have an address */
  230. if (addressed) {
  231. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  232. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  233. }
  234. /* Program data register, if we have data */
  235. if (in != NULL) {
  236. memcpy(&reg, in, len);
  237. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  238. }
  239. /* Issue read/write command */
  240. EFX_POPULATE_OWORD_7(reg,
  241. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  242. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  243. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  244. FRF_AB_EE_SPI_HCMD_READ, reading,
  245. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  246. FRF_AB_EE_SPI_HCMD_ADBCNT,
  247. (addressed ? spi->addr_len : 0),
  248. FRF_AB_EE_SPI_HCMD_ENC, command);
  249. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  250. /* Wait for read/write to complete */
  251. rc = falcon_spi_wait(efx);
  252. if (rc)
  253. return rc;
  254. /* Read data */
  255. if (out != NULL) {
  256. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  257. memcpy(out, &reg, len);
  258. }
  259. return 0;
  260. }
  261. static size_t
  262. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  263. {
  264. return min(FALCON_SPI_MAX_LEN,
  265. (spi->block_size - (start & (spi->block_size - 1))));
  266. }
  267. static inline u8
  268. efx_spi_munge_command(const struct efx_spi_device *spi,
  269. const u8 command, const unsigned int address)
  270. {
  271. return command | (((address >> 8) & spi->munge_address) << 3);
  272. }
  273. /* Wait up to 10 ms for buffered write completion */
  274. int
  275. falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi)
  276. {
  277. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  278. u8 status;
  279. int rc;
  280. for (;;) {
  281. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  282. &status, sizeof(status));
  283. if (rc)
  284. return rc;
  285. if (!(status & SPI_STATUS_NRDY))
  286. return 0;
  287. if (time_after_eq(jiffies, timeout)) {
  288. netif_err(efx, hw, efx->net_dev,
  289. "SPI write timeout on device %d"
  290. " last status=0x%02x\n",
  291. spi->device_id, status);
  292. return -ETIMEDOUT;
  293. }
  294. schedule_timeout_uninterruptible(1);
  295. }
  296. }
  297. int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi,
  298. loff_t start, size_t len, size_t *retlen, u8 *buffer)
  299. {
  300. size_t block_len, pos = 0;
  301. unsigned int command;
  302. int rc = 0;
  303. while (pos < len) {
  304. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  305. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  306. rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL,
  307. buffer + pos, block_len);
  308. if (rc)
  309. break;
  310. pos += block_len;
  311. /* Avoid locking up the system */
  312. cond_resched();
  313. if (signal_pending(current)) {
  314. rc = -EINTR;
  315. break;
  316. }
  317. }
  318. if (retlen)
  319. *retlen = pos;
  320. return rc;
  321. }
  322. int
  323. falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi,
  324. loff_t start, size_t len, size_t *retlen, const u8 *buffer)
  325. {
  326. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  327. size_t block_len, pos = 0;
  328. unsigned int command;
  329. int rc = 0;
  330. while (pos < len) {
  331. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  332. if (rc)
  333. break;
  334. block_len = min(len - pos,
  335. falcon_spi_write_limit(spi, start + pos));
  336. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  337. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  338. buffer + pos, NULL, block_len);
  339. if (rc)
  340. break;
  341. rc = falcon_spi_wait_write(efx, spi);
  342. if (rc)
  343. break;
  344. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  345. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  346. NULL, verify_buffer, block_len);
  347. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  348. rc = -EIO;
  349. break;
  350. }
  351. pos += block_len;
  352. /* Avoid locking up the system */
  353. cond_resched();
  354. if (signal_pending(current)) {
  355. rc = -EINTR;
  356. break;
  357. }
  358. }
  359. if (retlen)
  360. *retlen = pos;
  361. return rc;
  362. }
  363. /**************************************************************************
  364. *
  365. * MAC wrapper
  366. *
  367. **************************************************************************
  368. */
  369. static void falcon_push_multicast_hash(struct efx_nic *efx)
  370. {
  371. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  372. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  373. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  374. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  375. }
  376. static void falcon_reset_macs(struct efx_nic *efx)
  377. {
  378. struct falcon_nic_data *nic_data = efx->nic_data;
  379. efx_oword_t reg, mac_ctrl;
  380. int count;
  381. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  382. /* It's not safe to use GLB_CTL_REG to reset the
  383. * macs, so instead use the internal MAC resets
  384. */
  385. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  386. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  387. for (count = 0; count < 10000; count++) {
  388. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  389. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  390. 0)
  391. return;
  392. udelay(10);
  393. }
  394. netif_err(efx, hw, efx->net_dev,
  395. "timed out waiting for XMAC core reset\n");
  396. }
  397. /* Mac stats will fail whist the TX fifo is draining */
  398. WARN_ON(nic_data->stats_disable_count == 0);
  399. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  400. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  401. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  402. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  403. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  404. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  405. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  406. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  407. count = 0;
  408. while (1) {
  409. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  410. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  411. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  412. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  413. netif_dbg(efx, hw, efx->net_dev,
  414. "Completed MAC reset after %d loops\n",
  415. count);
  416. break;
  417. }
  418. if (count > 20) {
  419. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  420. break;
  421. }
  422. count++;
  423. udelay(10);
  424. }
  425. /* Ensure the correct MAC is selected before statistics
  426. * are re-enabled by the caller */
  427. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  428. falcon_setup_xaui(efx);
  429. }
  430. void falcon_drain_tx_fifo(struct efx_nic *efx)
  431. {
  432. efx_oword_t reg;
  433. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  434. (efx->loopback_mode != LOOPBACK_NONE))
  435. return;
  436. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  437. /* There is no point in draining more than once */
  438. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  439. return;
  440. falcon_reset_macs(efx);
  441. }
  442. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  443. {
  444. efx_oword_t reg;
  445. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  446. return;
  447. /* Isolate the MAC -> RX */
  448. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  449. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  450. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  451. /* Isolate TX -> MAC */
  452. falcon_drain_tx_fifo(efx);
  453. }
  454. void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  455. {
  456. struct efx_link_state *link_state = &efx->link_state;
  457. efx_oword_t reg;
  458. int link_speed, isolate;
  459. isolate = !!ACCESS_ONCE(efx->reset_pending);
  460. switch (link_state->speed) {
  461. case 10000: link_speed = 3; break;
  462. case 1000: link_speed = 2; break;
  463. case 100: link_speed = 1; break;
  464. default: link_speed = 0; break;
  465. }
  466. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  467. * as advertised. Disable to ensure packets are not
  468. * indefinitely held and TX queue can be flushed at any point
  469. * while the link is down. */
  470. EFX_POPULATE_OWORD_5(reg,
  471. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  472. FRF_AB_MAC_BCAD_ACPT, 1,
  473. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  474. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  475. FRF_AB_MAC_SPEED, link_speed);
  476. /* On B0, MAC backpressure can be disabled and packets get
  477. * discarded. */
  478. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  479. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  480. !link_state->up || isolate);
  481. }
  482. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  483. /* Restore the multicast hash registers. */
  484. falcon_push_multicast_hash(efx);
  485. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  486. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  487. * initialisation but it may read back as 0) */
  488. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  489. /* Unisolate the MAC -> RX */
  490. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  491. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  492. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  493. }
  494. static void falcon_stats_request(struct efx_nic *efx)
  495. {
  496. struct falcon_nic_data *nic_data = efx->nic_data;
  497. efx_oword_t reg;
  498. WARN_ON(nic_data->stats_pending);
  499. WARN_ON(nic_data->stats_disable_count);
  500. if (nic_data->stats_dma_done == NULL)
  501. return; /* no mac selected */
  502. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  503. nic_data->stats_pending = true;
  504. wmb(); /* ensure done flag is clear */
  505. /* Initiate DMA transfer of stats */
  506. EFX_POPULATE_OWORD_2(reg,
  507. FRF_AB_MAC_STAT_DMA_CMD, 1,
  508. FRF_AB_MAC_STAT_DMA_ADR,
  509. efx->stats_buffer.dma_addr);
  510. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  511. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  512. }
  513. static void falcon_stats_complete(struct efx_nic *efx)
  514. {
  515. struct falcon_nic_data *nic_data = efx->nic_data;
  516. if (!nic_data->stats_pending)
  517. return;
  518. nic_data->stats_pending = 0;
  519. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  520. rmb(); /* read the done flag before the stats */
  521. efx->mac_op->update_stats(efx);
  522. } else {
  523. netif_err(efx, hw, efx->net_dev,
  524. "timed out waiting for statistics\n");
  525. }
  526. }
  527. static void falcon_stats_timer_func(unsigned long context)
  528. {
  529. struct efx_nic *efx = (struct efx_nic *)context;
  530. struct falcon_nic_data *nic_data = efx->nic_data;
  531. spin_lock(&efx->stats_lock);
  532. falcon_stats_complete(efx);
  533. if (nic_data->stats_disable_count == 0)
  534. falcon_stats_request(efx);
  535. spin_unlock(&efx->stats_lock);
  536. }
  537. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  538. {
  539. struct efx_link_state old_state = efx->link_state;
  540. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  541. WARN_ON(!LOOPBACK_INTERNAL(efx));
  542. efx->link_state.fd = true;
  543. efx->link_state.fc = efx->wanted_fc;
  544. efx->link_state.up = true;
  545. efx->link_state.speed = 10000;
  546. return !efx_link_state_equal(&efx->link_state, &old_state);
  547. }
  548. static int falcon_reconfigure_port(struct efx_nic *efx)
  549. {
  550. int rc;
  551. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  552. /* Poll the PHY link state *before* reconfiguring it. This means we
  553. * will pick up the correct speed (in loopback) to select the correct
  554. * MAC.
  555. */
  556. if (LOOPBACK_INTERNAL(efx))
  557. falcon_loopback_link_poll(efx);
  558. else
  559. efx->phy_op->poll(efx);
  560. falcon_stop_nic_stats(efx);
  561. falcon_deconfigure_mac_wrapper(efx);
  562. falcon_reset_macs(efx);
  563. efx->phy_op->reconfigure(efx);
  564. rc = efx->mac_op->reconfigure(efx);
  565. BUG_ON(rc);
  566. falcon_start_nic_stats(efx);
  567. /* Synchronise efx->link_state with the kernel */
  568. efx_link_status_changed(efx);
  569. return 0;
  570. }
  571. /**************************************************************************
  572. *
  573. * PHY access via GMII
  574. *
  575. **************************************************************************
  576. */
  577. /* Wait for GMII access to complete */
  578. static int falcon_gmii_wait(struct efx_nic *efx)
  579. {
  580. efx_oword_t md_stat;
  581. int count;
  582. /* wait up to 50ms - taken max from datasheet */
  583. for (count = 0; count < 5000; count++) {
  584. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  585. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  586. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  587. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  588. netif_err(efx, hw, efx->net_dev,
  589. "error from GMII access "
  590. EFX_OWORD_FMT"\n",
  591. EFX_OWORD_VAL(md_stat));
  592. return -EIO;
  593. }
  594. return 0;
  595. }
  596. udelay(10);
  597. }
  598. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  599. return -ETIMEDOUT;
  600. }
  601. /* Write an MDIO register of a PHY connected to Falcon. */
  602. static int falcon_mdio_write(struct net_device *net_dev,
  603. int prtad, int devad, u16 addr, u16 value)
  604. {
  605. struct efx_nic *efx = netdev_priv(net_dev);
  606. struct falcon_nic_data *nic_data = efx->nic_data;
  607. efx_oword_t reg;
  608. int rc;
  609. netif_vdbg(efx, hw, efx->net_dev,
  610. "writing MDIO %d register %d.%d with 0x%04x\n",
  611. prtad, devad, addr, value);
  612. mutex_lock(&nic_data->mdio_lock);
  613. /* Check MDIO not currently being accessed */
  614. rc = falcon_gmii_wait(efx);
  615. if (rc)
  616. goto out;
  617. /* Write the address/ID register */
  618. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  619. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  620. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  621. FRF_AB_MD_DEV_ADR, devad);
  622. efx_writeo(efx, &reg, FR_AB_MD_ID);
  623. /* Write data */
  624. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  625. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  626. EFX_POPULATE_OWORD_2(reg,
  627. FRF_AB_MD_WRC, 1,
  628. FRF_AB_MD_GC, 0);
  629. efx_writeo(efx, &reg, FR_AB_MD_CS);
  630. /* Wait for data to be written */
  631. rc = falcon_gmii_wait(efx);
  632. if (rc) {
  633. /* Abort the write operation */
  634. EFX_POPULATE_OWORD_2(reg,
  635. FRF_AB_MD_WRC, 0,
  636. FRF_AB_MD_GC, 1);
  637. efx_writeo(efx, &reg, FR_AB_MD_CS);
  638. udelay(10);
  639. }
  640. out:
  641. mutex_unlock(&nic_data->mdio_lock);
  642. return rc;
  643. }
  644. /* Read an MDIO register of a PHY connected to Falcon. */
  645. static int falcon_mdio_read(struct net_device *net_dev,
  646. int prtad, int devad, u16 addr)
  647. {
  648. struct efx_nic *efx = netdev_priv(net_dev);
  649. struct falcon_nic_data *nic_data = efx->nic_data;
  650. efx_oword_t reg;
  651. int rc;
  652. mutex_lock(&nic_data->mdio_lock);
  653. /* Check MDIO not currently being accessed */
  654. rc = falcon_gmii_wait(efx);
  655. if (rc)
  656. goto out;
  657. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  658. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  659. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  660. FRF_AB_MD_DEV_ADR, devad);
  661. efx_writeo(efx, &reg, FR_AB_MD_ID);
  662. /* Request data to be read */
  663. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  664. efx_writeo(efx, &reg, FR_AB_MD_CS);
  665. /* Wait for data to become available */
  666. rc = falcon_gmii_wait(efx);
  667. if (rc == 0) {
  668. efx_reado(efx, &reg, FR_AB_MD_RXD);
  669. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  670. netif_vdbg(efx, hw, efx->net_dev,
  671. "read from MDIO %d register %d.%d, got %04x\n",
  672. prtad, devad, addr, rc);
  673. } else {
  674. /* Abort the read operation */
  675. EFX_POPULATE_OWORD_2(reg,
  676. FRF_AB_MD_RIC, 0,
  677. FRF_AB_MD_GC, 1);
  678. efx_writeo(efx, &reg, FR_AB_MD_CS);
  679. netif_dbg(efx, hw, efx->net_dev,
  680. "read from MDIO %d register %d.%d, got error %d\n",
  681. prtad, devad, addr, rc);
  682. }
  683. out:
  684. mutex_unlock(&nic_data->mdio_lock);
  685. return rc;
  686. }
  687. /* This call is responsible for hooking in the MAC and PHY operations */
  688. static int falcon_probe_port(struct efx_nic *efx)
  689. {
  690. struct falcon_nic_data *nic_data = efx->nic_data;
  691. int rc;
  692. switch (efx->phy_type) {
  693. case PHY_TYPE_SFX7101:
  694. efx->phy_op = &falcon_sfx7101_phy_ops;
  695. break;
  696. case PHY_TYPE_QT2022C2:
  697. case PHY_TYPE_QT2025C:
  698. efx->phy_op = &falcon_qt202x_phy_ops;
  699. break;
  700. case PHY_TYPE_TXC43128:
  701. efx->phy_op = &falcon_txc_phy_ops;
  702. break;
  703. default:
  704. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  705. efx->phy_type);
  706. return -ENODEV;
  707. }
  708. /* Fill out MDIO structure and loopback modes */
  709. mutex_init(&nic_data->mdio_lock);
  710. efx->mdio.mdio_read = falcon_mdio_read;
  711. efx->mdio.mdio_write = falcon_mdio_write;
  712. rc = efx->phy_op->probe(efx);
  713. if (rc != 0)
  714. return rc;
  715. /* Initial assumption */
  716. efx->link_state.speed = 10000;
  717. efx->link_state.fd = true;
  718. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  719. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  720. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  721. else
  722. efx->wanted_fc = EFX_FC_RX;
  723. if (efx->mdio.mmds & MDIO_DEVS_AN)
  724. efx->wanted_fc |= EFX_FC_AUTO;
  725. /* Allocate buffer for stats */
  726. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  727. FALCON_MAC_STATS_SIZE);
  728. if (rc)
  729. return rc;
  730. netif_dbg(efx, probe, efx->net_dev,
  731. "stats buffer at %llx (virt %p phys %llx)\n",
  732. (u64)efx->stats_buffer.dma_addr,
  733. efx->stats_buffer.addr,
  734. (u64)virt_to_phys(efx->stats_buffer.addr));
  735. nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset;
  736. return 0;
  737. }
  738. static void falcon_remove_port(struct efx_nic *efx)
  739. {
  740. efx->phy_op->remove(efx);
  741. efx_nic_free_buffer(efx, &efx->stats_buffer);
  742. }
  743. /* Global events are basically PHY events */
  744. static bool
  745. falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  746. {
  747. struct efx_nic *efx = channel->efx;
  748. struct falcon_nic_data *nic_data = efx->nic_data;
  749. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  750. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  751. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR))
  752. /* Ignored */
  753. return true;
  754. if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) &&
  755. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  756. nic_data->xmac_poll_required = true;
  757. return true;
  758. }
  759. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  760. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  761. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  762. netif_err(efx, rx_err, efx->net_dev,
  763. "channel %d seen global RX_RESET event. Resetting.\n",
  764. channel->channel);
  765. atomic_inc(&efx->rx_reset);
  766. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  767. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  768. return true;
  769. }
  770. return false;
  771. }
  772. /**************************************************************************
  773. *
  774. * Falcon test code
  775. *
  776. **************************************************************************/
  777. static int
  778. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  779. {
  780. struct falcon_nic_data *nic_data = efx->nic_data;
  781. struct falcon_nvconfig *nvconfig;
  782. struct efx_spi_device *spi;
  783. void *region;
  784. int rc, magic_num, struct_ver;
  785. __le16 *word, *limit;
  786. u32 csum;
  787. if (efx_spi_present(&nic_data->spi_flash))
  788. spi = &nic_data->spi_flash;
  789. else if (efx_spi_present(&nic_data->spi_eeprom))
  790. spi = &nic_data->spi_eeprom;
  791. else
  792. return -EINVAL;
  793. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  794. if (!region)
  795. return -ENOMEM;
  796. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  797. mutex_lock(&nic_data->spi_lock);
  798. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  799. mutex_unlock(&nic_data->spi_lock);
  800. if (rc) {
  801. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  802. efx_spi_present(&nic_data->spi_flash) ?
  803. "flash" : "EEPROM");
  804. rc = -EIO;
  805. goto out;
  806. }
  807. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  808. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  809. rc = -EINVAL;
  810. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  811. netif_err(efx, hw, efx->net_dev,
  812. "NVRAM bad magic 0x%x\n", magic_num);
  813. goto out;
  814. }
  815. if (struct_ver < 2) {
  816. netif_err(efx, hw, efx->net_dev,
  817. "NVRAM has ancient version 0x%x\n", struct_ver);
  818. goto out;
  819. } else if (struct_ver < 4) {
  820. word = &nvconfig->board_magic_num;
  821. limit = (__le16 *) (nvconfig + 1);
  822. } else {
  823. word = region;
  824. limit = region + FALCON_NVCONFIG_END;
  825. }
  826. for (csum = 0; word < limit; ++word)
  827. csum += le16_to_cpu(*word);
  828. if (~csum & 0xffff) {
  829. netif_err(efx, hw, efx->net_dev,
  830. "NVRAM has incorrect checksum\n");
  831. goto out;
  832. }
  833. rc = 0;
  834. if (nvconfig_out)
  835. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  836. out:
  837. kfree(region);
  838. return rc;
  839. }
  840. static int falcon_test_nvram(struct efx_nic *efx)
  841. {
  842. return falcon_read_nvram(efx, NULL);
  843. }
  844. static const struct efx_nic_register_test falcon_b0_register_tests[] = {
  845. { FR_AZ_ADR_REGION,
  846. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  847. { FR_AZ_RX_CFG,
  848. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  849. { FR_AZ_TX_CFG,
  850. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  851. { FR_AZ_TX_RESERVED,
  852. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  853. { FR_AB_MAC_CTRL,
  854. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  855. { FR_AZ_SRM_TX_DC_CFG,
  856. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  857. { FR_AZ_RX_DC_CFG,
  858. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  859. { FR_AZ_RX_DC_PF_WM,
  860. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  861. { FR_BZ_DP_CTRL,
  862. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  863. { FR_AB_GM_CFG2,
  864. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  865. { FR_AB_GMF_CFG0,
  866. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  867. { FR_AB_XM_GLB_CFG,
  868. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  869. { FR_AB_XM_TX_CFG,
  870. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  871. { FR_AB_XM_RX_CFG,
  872. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  873. { FR_AB_XM_RX_PARAM,
  874. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  875. { FR_AB_XM_FC,
  876. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  877. { FR_AB_XM_ADR_LO,
  878. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  879. { FR_AB_XX_SD_CTL,
  880. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  881. };
  882. static int falcon_b0_test_registers(struct efx_nic *efx)
  883. {
  884. return efx_nic_test_registers(efx, falcon_b0_register_tests,
  885. ARRAY_SIZE(falcon_b0_register_tests));
  886. }
  887. /**************************************************************************
  888. *
  889. * Device reset
  890. *
  891. **************************************************************************
  892. */
  893. static enum reset_type falcon_map_reset_reason(enum reset_type reason)
  894. {
  895. switch (reason) {
  896. case RESET_TYPE_RX_RECOVERY:
  897. case RESET_TYPE_RX_DESC_FETCH:
  898. case RESET_TYPE_TX_DESC_FETCH:
  899. case RESET_TYPE_TX_SKIP:
  900. /* These can occasionally occur due to hardware bugs.
  901. * We try to reset without disrupting the link.
  902. */
  903. return RESET_TYPE_INVISIBLE;
  904. default:
  905. return RESET_TYPE_ALL;
  906. }
  907. }
  908. static int falcon_map_reset_flags(u32 *flags)
  909. {
  910. enum {
  911. FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  912. ETH_RESET_OFFLOAD | ETH_RESET_MAC),
  913. FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY,
  914. FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ,
  915. };
  916. if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
  917. *flags &= ~FALCON_RESET_WORLD;
  918. return RESET_TYPE_WORLD;
  919. }
  920. if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
  921. *flags &= ~FALCON_RESET_ALL;
  922. return RESET_TYPE_ALL;
  923. }
  924. if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
  925. *flags &= ~FALCON_RESET_INVISIBLE;
  926. return RESET_TYPE_INVISIBLE;
  927. }
  928. return -EINVAL;
  929. }
  930. /* Resets NIC to known state. This routine must be called in process
  931. * context and is allowed to sleep. */
  932. static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  933. {
  934. struct falcon_nic_data *nic_data = efx->nic_data;
  935. efx_oword_t glb_ctl_reg_ker;
  936. int rc;
  937. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  938. RESET_TYPE(method));
  939. /* Initiate device reset */
  940. if (method == RESET_TYPE_WORLD) {
  941. rc = pci_save_state(efx->pci_dev);
  942. if (rc) {
  943. netif_err(efx, drv, efx->net_dev,
  944. "failed to backup PCI state of primary "
  945. "function prior to hardware reset\n");
  946. goto fail1;
  947. }
  948. if (efx_nic_is_dual_func(efx)) {
  949. rc = pci_save_state(nic_data->pci_dev2);
  950. if (rc) {
  951. netif_err(efx, drv, efx->net_dev,
  952. "failed to backup PCI state of "
  953. "secondary function prior to "
  954. "hardware reset\n");
  955. goto fail2;
  956. }
  957. }
  958. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  959. FRF_AB_EXT_PHY_RST_DUR,
  960. FFE_AB_EXT_PHY_RST_DUR_10240US,
  961. FRF_AB_SWRST, 1);
  962. } else {
  963. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  964. /* exclude PHY from "invisible" reset */
  965. FRF_AB_EXT_PHY_RST_CTL,
  966. method == RESET_TYPE_INVISIBLE,
  967. /* exclude EEPROM/flash and PCIe */
  968. FRF_AB_PCIE_CORE_RST_CTL, 1,
  969. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  970. FRF_AB_PCIE_SD_RST_CTL, 1,
  971. FRF_AB_EE_RST_CTL, 1,
  972. FRF_AB_EXT_PHY_RST_DUR,
  973. FFE_AB_EXT_PHY_RST_DUR_10240US,
  974. FRF_AB_SWRST, 1);
  975. }
  976. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  977. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  978. schedule_timeout_uninterruptible(HZ / 20);
  979. /* Restore PCI configuration if needed */
  980. if (method == RESET_TYPE_WORLD) {
  981. if (efx_nic_is_dual_func(efx))
  982. pci_restore_state(nic_data->pci_dev2);
  983. pci_restore_state(efx->pci_dev);
  984. netif_dbg(efx, drv, efx->net_dev,
  985. "successfully restored PCI config\n");
  986. }
  987. /* Assert that reset complete */
  988. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  989. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  990. rc = -ETIMEDOUT;
  991. netif_err(efx, hw, efx->net_dev,
  992. "timed out waiting for hardware reset\n");
  993. goto fail3;
  994. }
  995. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  996. return 0;
  997. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  998. fail2:
  999. pci_restore_state(efx->pci_dev);
  1000. fail1:
  1001. fail3:
  1002. return rc;
  1003. }
  1004. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1005. {
  1006. struct falcon_nic_data *nic_data = efx->nic_data;
  1007. int rc;
  1008. mutex_lock(&nic_data->spi_lock);
  1009. rc = __falcon_reset_hw(efx, method);
  1010. mutex_unlock(&nic_data->spi_lock);
  1011. return rc;
  1012. }
  1013. static void falcon_monitor(struct efx_nic *efx)
  1014. {
  1015. bool link_changed;
  1016. int rc;
  1017. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1018. rc = falcon_board(efx)->type->monitor(efx);
  1019. if (rc) {
  1020. netif_err(efx, hw, efx->net_dev,
  1021. "Board sensor %s; shutting down PHY\n",
  1022. (rc == -ERANGE) ? "reported fault" : "failed");
  1023. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1024. rc = __efx_reconfigure_port(efx);
  1025. WARN_ON(rc);
  1026. }
  1027. if (LOOPBACK_INTERNAL(efx))
  1028. link_changed = falcon_loopback_link_poll(efx);
  1029. else
  1030. link_changed = efx->phy_op->poll(efx);
  1031. if (link_changed) {
  1032. falcon_stop_nic_stats(efx);
  1033. falcon_deconfigure_mac_wrapper(efx);
  1034. falcon_reset_macs(efx);
  1035. rc = efx->mac_op->reconfigure(efx);
  1036. BUG_ON(rc);
  1037. falcon_start_nic_stats(efx);
  1038. efx_link_status_changed(efx);
  1039. }
  1040. falcon_poll_xmac(efx);
  1041. }
  1042. /* Zeroes out the SRAM contents. This routine must be called in
  1043. * process context and is allowed to sleep.
  1044. */
  1045. static int falcon_reset_sram(struct efx_nic *efx)
  1046. {
  1047. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1048. int count;
  1049. /* Set the SRAM wake/sleep GPIO appropriately. */
  1050. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1051. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1052. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1053. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1054. /* Initiate SRAM reset */
  1055. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1056. FRF_AZ_SRM_INIT_EN, 1,
  1057. FRF_AZ_SRM_NB_SZ, 0);
  1058. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1059. /* Wait for SRAM reset to complete */
  1060. count = 0;
  1061. do {
  1062. netif_dbg(efx, hw, efx->net_dev,
  1063. "waiting for SRAM reset (attempt %d)...\n", count);
  1064. /* SRAM reset is slow; expect around 16ms */
  1065. schedule_timeout_uninterruptible(HZ / 50);
  1066. /* Check for reset complete */
  1067. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1068. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1069. netif_dbg(efx, hw, efx->net_dev,
  1070. "SRAM reset complete\n");
  1071. return 0;
  1072. }
  1073. } while (++count < 20); /* wait up to 0.4 sec */
  1074. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1075. return -ETIMEDOUT;
  1076. }
  1077. static void falcon_spi_device_init(struct efx_nic *efx,
  1078. struct efx_spi_device *spi_device,
  1079. unsigned int device_id, u32 device_type)
  1080. {
  1081. if (device_type != 0) {
  1082. spi_device->device_id = device_id;
  1083. spi_device->size =
  1084. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1085. spi_device->addr_len =
  1086. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1087. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1088. spi_device->addr_len == 1);
  1089. spi_device->erase_command =
  1090. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1091. spi_device->erase_size =
  1092. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1093. SPI_DEV_TYPE_ERASE_SIZE);
  1094. spi_device->block_size =
  1095. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1096. SPI_DEV_TYPE_BLOCK_SIZE);
  1097. } else {
  1098. spi_device->size = 0;
  1099. }
  1100. }
  1101. /* Extract non-volatile configuration */
  1102. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1103. {
  1104. struct falcon_nic_data *nic_data = efx->nic_data;
  1105. struct falcon_nvconfig *nvconfig;
  1106. int rc;
  1107. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1108. if (!nvconfig)
  1109. return -ENOMEM;
  1110. rc = falcon_read_nvram(efx, nvconfig);
  1111. if (rc)
  1112. goto out;
  1113. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1114. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1115. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1116. falcon_spi_device_init(
  1117. efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1118. le32_to_cpu(nvconfig->board_v3
  1119. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1120. falcon_spi_device_init(
  1121. efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1122. le32_to_cpu(nvconfig->board_v3
  1123. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1124. }
  1125. /* Read the MAC addresses */
  1126. memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN);
  1127. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1128. efx->phy_type, efx->mdio.prtad);
  1129. rc = falcon_probe_board(efx,
  1130. le16_to_cpu(nvconfig->board_v2.board_revision));
  1131. out:
  1132. kfree(nvconfig);
  1133. return rc;
  1134. }
  1135. /* Probe all SPI devices on the NIC */
  1136. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1137. {
  1138. struct falcon_nic_data *nic_data = efx->nic_data;
  1139. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1140. int boot_dev;
  1141. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1142. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1143. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1144. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1145. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1146. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1147. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1148. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1149. "flash" : "EEPROM");
  1150. } else {
  1151. /* Disable VPD and set clock dividers to safe
  1152. * values for initial programming. */
  1153. boot_dev = -1;
  1154. netif_dbg(efx, probe, efx->net_dev,
  1155. "Booted from internal ASIC settings;"
  1156. " setting SPI config\n");
  1157. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1158. /* 125 MHz / 7 ~= 20 MHz */
  1159. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1160. /* 125 MHz / 63 ~= 2 MHz */
  1161. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1162. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1163. }
  1164. mutex_init(&nic_data->spi_lock);
  1165. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1166. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1167. FFE_AB_SPI_DEVICE_FLASH,
  1168. default_flash_type);
  1169. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1170. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1171. FFE_AB_SPI_DEVICE_EEPROM,
  1172. large_eeprom_type);
  1173. }
  1174. static int falcon_probe_nic(struct efx_nic *efx)
  1175. {
  1176. struct falcon_nic_data *nic_data;
  1177. struct falcon_board *board;
  1178. int rc;
  1179. /* Allocate storage for hardware specific data */
  1180. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1181. if (!nic_data)
  1182. return -ENOMEM;
  1183. efx->nic_data = nic_data;
  1184. rc = -ENODEV;
  1185. if (efx_nic_fpga_ver(efx) != 0) {
  1186. netif_err(efx, probe, efx->net_dev,
  1187. "Falcon FPGA not supported\n");
  1188. goto fail1;
  1189. }
  1190. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1191. efx_oword_t nic_stat;
  1192. struct pci_dev *dev;
  1193. u8 pci_rev = efx->pci_dev->revision;
  1194. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1195. netif_err(efx, probe, efx->net_dev,
  1196. "Falcon rev A0 not supported\n");
  1197. goto fail1;
  1198. }
  1199. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1200. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1201. netif_err(efx, probe, efx->net_dev,
  1202. "Falcon rev A1 1G not supported\n");
  1203. goto fail1;
  1204. }
  1205. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1206. netif_err(efx, probe, efx->net_dev,
  1207. "Falcon rev A1 PCI-X not supported\n");
  1208. goto fail1;
  1209. }
  1210. dev = pci_dev_get(efx->pci_dev);
  1211. while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
  1212. dev))) {
  1213. if (dev->bus == efx->pci_dev->bus &&
  1214. dev->devfn == efx->pci_dev->devfn + 1) {
  1215. nic_data->pci_dev2 = dev;
  1216. break;
  1217. }
  1218. }
  1219. if (!nic_data->pci_dev2) {
  1220. netif_err(efx, probe, efx->net_dev,
  1221. "failed to find secondary function\n");
  1222. rc = -ENODEV;
  1223. goto fail2;
  1224. }
  1225. }
  1226. /* Now we can reset the NIC */
  1227. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1228. if (rc) {
  1229. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1230. goto fail3;
  1231. }
  1232. /* Allocate memory for INT_KER */
  1233. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  1234. if (rc)
  1235. goto fail4;
  1236. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1237. netif_dbg(efx, probe, efx->net_dev,
  1238. "INT_KER at %llx (virt %p phys %llx)\n",
  1239. (u64)efx->irq_status.dma_addr,
  1240. efx->irq_status.addr,
  1241. (u64)virt_to_phys(efx->irq_status.addr));
  1242. falcon_probe_spi_devices(efx);
  1243. /* Read in the non-volatile configuration */
  1244. rc = falcon_probe_nvconfig(efx);
  1245. if (rc) {
  1246. if (rc == -EINVAL)
  1247. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1248. goto fail5;
  1249. }
  1250. /* Initialise I2C adapter */
  1251. board = falcon_board(efx);
  1252. board->i2c_adap.owner = THIS_MODULE;
  1253. board->i2c_data = falcon_i2c_bit_operations;
  1254. board->i2c_data.data = efx;
  1255. board->i2c_adap.algo_data = &board->i2c_data;
  1256. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1257. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1258. sizeof(board->i2c_adap.name));
  1259. rc = i2c_bit_add_bus(&board->i2c_adap);
  1260. if (rc)
  1261. goto fail5;
  1262. rc = falcon_board(efx)->type->init(efx);
  1263. if (rc) {
  1264. netif_err(efx, probe, efx->net_dev,
  1265. "failed to initialise board\n");
  1266. goto fail6;
  1267. }
  1268. nic_data->stats_disable_count = 1;
  1269. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1270. (unsigned long)efx);
  1271. return 0;
  1272. fail6:
  1273. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  1274. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1275. fail5:
  1276. efx_nic_free_buffer(efx, &efx->irq_status);
  1277. fail4:
  1278. fail3:
  1279. if (nic_data->pci_dev2) {
  1280. pci_dev_put(nic_data->pci_dev2);
  1281. nic_data->pci_dev2 = NULL;
  1282. }
  1283. fail2:
  1284. fail1:
  1285. kfree(efx->nic_data);
  1286. return rc;
  1287. }
  1288. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1289. {
  1290. /* Prior to Siena the RX DMA engine will split each frame at
  1291. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  1292. * be so large that that never happens. */
  1293. const unsigned huge_buf_size = (3 * 4096) >> 5;
  1294. /* RX control FIFO thresholds (32 entries) */
  1295. const unsigned ctrl_xon_thr = 20;
  1296. const unsigned ctrl_xoff_thr = 25;
  1297. efx_oword_t reg;
  1298. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1299. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1300. /* Data FIFO size is 5.5K */
  1301. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1302. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1303. huge_buf_size);
  1304. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  1305. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  1306. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1307. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1308. } else {
  1309. /* Data FIFO size is 80K; register fields moved */
  1310. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1311. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1312. huge_buf_size);
  1313. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  1314. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  1315. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  1316. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1317. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1318. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1319. /* Enable hash insertion. This is broken for the
  1320. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1321. * IPv4 hashes. */
  1322. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1323. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1324. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1325. }
  1326. /* Always enable XOFF signal from RX FIFO. We enable
  1327. * or disable transmission of pause frames at the MAC. */
  1328. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1329. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1330. }
  1331. /* This call performs hardware-specific global initialisation, such as
  1332. * defining the descriptor cache sizes and number of RSS channels.
  1333. * It does not set up any buffers, descriptor rings or event queues.
  1334. */
  1335. static int falcon_init_nic(struct efx_nic *efx)
  1336. {
  1337. efx_oword_t temp;
  1338. int rc;
  1339. /* Use on-chip SRAM */
  1340. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1341. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1342. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1343. rc = falcon_reset_sram(efx);
  1344. if (rc)
  1345. return rc;
  1346. /* Clear the parity enables on the TX data fifos as
  1347. * they produce false parity errors because of timing issues
  1348. */
  1349. if (EFX_WORKAROUND_5129(efx)) {
  1350. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1351. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1352. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1353. }
  1354. if (EFX_WORKAROUND_7244(efx)) {
  1355. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1356. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1357. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1358. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1359. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1360. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1361. }
  1362. /* XXX This is documented only for Falcon A0/A1 */
  1363. /* Setup RX. Wait for descriptor is broken and must
  1364. * be disabled. RXDP recovery shouldn't be needed, but is.
  1365. */
  1366. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1367. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1368. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1369. if (EFX_WORKAROUND_5583(efx))
  1370. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1371. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1372. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1373. * descriptors (which is bad).
  1374. */
  1375. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1376. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1377. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1378. falcon_init_rx_cfg(efx);
  1379. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1380. /* Set hash key for IPv4 */
  1381. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1382. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1383. /* Set destination of both TX and RX Flush events */
  1384. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1385. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1386. }
  1387. efx_nic_init_common(efx);
  1388. return 0;
  1389. }
  1390. static void falcon_remove_nic(struct efx_nic *efx)
  1391. {
  1392. struct falcon_nic_data *nic_data = efx->nic_data;
  1393. struct falcon_board *board = falcon_board(efx);
  1394. int rc;
  1395. board->type->fini(efx);
  1396. /* Remove I2C adapter and clear it in preparation for a retry */
  1397. rc = i2c_del_adapter(&board->i2c_adap);
  1398. BUG_ON(rc);
  1399. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1400. efx_nic_free_buffer(efx, &efx->irq_status);
  1401. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1402. /* Release the second function after the reset */
  1403. if (nic_data->pci_dev2) {
  1404. pci_dev_put(nic_data->pci_dev2);
  1405. nic_data->pci_dev2 = NULL;
  1406. }
  1407. /* Tear down the private nic state */
  1408. kfree(efx->nic_data);
  1409. efx->nic_data = NULL;
  1410. }
  1411. static void falcon_update_nic_stats(struct efx_nic *efx)
  1412. {
  1413. struct falcon_nic_data *nic_data = efx->nic_data;
  1414. efx_oword_t cnt;
  1415. if (nic_data->stats_disable_count)
  1416. return;
  1417. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1418. efx->n_rx_nodesc_drop_cnt +=
  1419. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1420. if (nic_data->stats_pending &&
  1421. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1422. nic_data->stats_pending = false;
  1423. rmb(); /* read the done flag before the stats */
  1424. efx->mac_op->update_stats(efx);
  1425. }
  1426. }
  1427. void falcon_start_nic_stats(struct efx_nic *efx)
  1428. {
  1429. struct falcon_nic_data *nic_data = efx->nic_data;
  1430. spin_lock_bh(&efx->stats_lock);
  1431. if (--nic_data->stats_disable_count == 0)
  1432. falcon_stats_request(efx);
  1433. spin_unlock_bh(&efx->stats_lock);
  1434. }
  1435. void falcon_stop_nic_stats(struct efx_nic *efx)
  1436. {
  1437. struct falcon_nic_data *nic_data = efx->nic_data;
  1438. int i;
  1439. might_sleep();
  1440. spin_lock_bh(&efx->stats_lock);
  1441. ++nic_data->stats_disable_count;
  1442. spin_unlock_bh(&efx->stats_lock);
  1443. del_timer_sync(&nic_data->stats_timer);
  1444. /* Wait enough time for the most recent transfer to
  1445. * complete. */
  1446. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1447. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1448. break;
  1449. msleep(1);
  1450. }
  1451. spin_lock_bh(&efx->stats_lock);
  1452. falcon_stats_complete(efx);
  1453. spin_unlock_bh(&efx->stats_lock);
  1454. }
  1455. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1456. {
  1457. falcon_board(efx)->type->set_id_led(efx, mode);
  1458. }
  1459. /**************************************************************************
  1460. *
  1461. * Wake on LAN
  1462. *
  1463. **************************************************************************
  1464. */
  1465. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1466. {
  1467. wol->supported = 0;
  1468. wol->wolopts = 0;
  1469. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1470. }
  1471. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1472. {
  1473. if (type != 0)
  1474. return -EINVAL;
  1475. return 0;
  1476. }
  1477. /**************************************************************************
  1478. *
  1479. * Revision-dependent attributes used by efx.c and nic.c
  1480. *
  1481. **************************************************************************
  1482. */
  1483. const struct efx_nic_type falcon_a1_nic_type = {
  1484. .probe = falcon_probe_nic,
  1485. .remove = falcon_remove_nic,
  1486. .init = falcon_init_nic,
  1487. .fini = efx_port_dummy_op_void,
  1488. .monitor = falcon_monitor,
  1489. .map_reset_reason = falcon_map_reset_reason,
  1490. .map_reset_flags = falcon_map_reset_flags,
  1491. .reset = falcon_reset_hw,
  1492. .probe_port = falcon_probe_port,
  1493. .remove_port = falcon_remove_port,
  1494. .handle_global_event = falcon_handle_global_event,
  1495. .prepare_flush = falcon_prepare_flush,
  1496. .update_stats = falcon_update_nic_stats,
  1497. .start_stats = falcon_start_nic_stats,
  1498. .stop_stats = falcon_stop_nic_stats,
  1499. .set_id_led = falcon_set_id_led,
  1500. .push_irq_moderation = falcon_push_irq_moderation,
  1501. .push_multicast_hash = falcon_push_multicast_hash,
  1502. .reconfigure_port = falcon_reconfigure_port,
  1503. .get_wol = falcon_get_wol,
  1504. .set_wol = falcon_set_wol,
  1505. .resume_wol = efx_port_dummy_op_void,
  1506. .test_nvram = falcon_test_nvram,
  1507. .default_mac_ops = &falcon_xmac_operations,
  1508. .revision = EFX_REV_FALCON_A1,
  1509. .mem_map_size = 0x20000,
  1510. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  1511. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  1512. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  1513. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  1514. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  1515. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1516. .rx_buffer_padding = 0x24,
  1517. .max_interrupt_mode = EFX_INT_MODE_MSI,
  1518. .phys_addr_channels = 4,
  1519. .tx_dc_base = 0x130000,
  1520. .rx_dc_base = 0x100000,
  1521. .offload_features = NETIF_F_IP_CSUM,
  1522. };
  1523. const struct efx_nic_type falcon_b0_nic_type = {
  1524. .probe = falcon_probe_nic,
  1525. .remove = falcon_remove_nic,
  1526. .init = falcon_init_nic,
  1527. .fini = efx_port_dummy_op_void,
  1528. .monitor = falcon_monitor,
  1529. .map_reset_reason = falcon_map_reset_reason,
  1530. .map_reset_flags = falcon_map_reset_flags,
  1531. .reset = falcon_reset_hw,
  1532. .probe_port = falcon_probe_port,
  1533. .remove_port = falcon_remove_port,
  1534. .handle_global_event = falcon_handle_global_event,
  1535. .prepare_flush = falcon_prepare_flush,
  1536. .update_stats = falcon_update_nic_stats,
  1537. .start_stats = falcon_start_nic_stats,
  1538. .stop_stats = falcon_stop_nic_stats,
  1539. .set_id_led = falcon_set_id_led,
  1540. .push_irq_moderation = falcon_push_irq_moderation,
  1541. .push_multicast_hash = falcon_push_multicast_hash,
  1542. .reconfigure_port = falcon_reconfigure_port,
  1543. .get_wol = falcon_get_wol,
  1544. .set_wol = falcon_set_wol,
  1545. .resume_wol = efx_port_dummy_op_void,
  1546. .test_registers = falcon_b0_test_registers,
  1547. .test_nvram = falcon_test_nvram,
  1548. .default_mac_ops = &falcon_xmac_operations,
  1549. .revision = EFX_REV_FALCON_B0,
  1550. /* Map everything up to and including the RSS indirection
  1551. * table. Don't map MSI-X table, MSI-X PBA since Linux
  1552. * requires that they not be mapped. */
  1553. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  1554. FR_BZ_RX_INDIRECTION_TBL_STEP *
  1555. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  1556. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  1557. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  1558. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  1559. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  1560. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  1561. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1562. .rx_buffer_hash_size = 0x10,
  1563. .rx_buffer_padding = 0,
  1564. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  1565. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  1566. * interrupt handler only supports 32
  1567. * channels */
  1568. .tx_dc_base = 0x130000,
  1569. .rx_dc_base = 0x100000,
  1570. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  1571. };