falcon.c 52 KB

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