falcon.c 50 KB

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