falcon.c 51 KB

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