falcon.c 50 KB

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