falcon.c 49 KB

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