falcon.c 49 KB

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