falcon.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  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. /* Probe all SPI devices on the NIC */
  1132. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1133. {
  1134. struct falcon_nic_data *nic_data = efx->nic_data;
  1135. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1136. int boot_dev;
  1137. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1138. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1139. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1140. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1141. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1142. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1143. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1144. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1145. "flash" : "EEPROM");
  1146. } else {
  1147. /* Disable VPD and set clock dividers to safe
  1148. * values for initial programming. */
  1149. boot_dev = -1;
  1150. netif_dbg(efx, probe, efx->net_dev,
  1151. "Booted from internal ASIC settings;"
  1152. " setting SPI config\n");
  1153. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1154. /* 125 MHz / 7 ~= 20 MHz */
  1155. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1156. /* 125 MHz / 63 ~= 2 MHz */
  1157. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1158. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1159. }
  1160. mutex_init(&nic_data->spi_lock);
  1161. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1162. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1163. FFE_AB_SPI_DEVICE_FLASH,
  1164. default_flash_type);
  1165. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1166. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1167. FFE_AB_SPI_DEVICE_EEPROM,
  1168. large_eeprom_type);
  1169. }
  1170. static int falcon_probe_nic(struct efx_nic *efx)
  1171. {
  1172. struct falcon_nic_data *nic_data;
  1173. struct falcon_board *board;
  1174. int rc;
  1175. /* Allocate storage for hardware specific data */
  1176. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1177. if (!nic_data)
  1178. return -ENOMEM;
  1179. efx->nic_data = nic_data;
  1180. rc = -ENODEV;
  1181. if (efx_nic_fpga_ver(efx) != 0) {
  1182. netif_err(efx, probe, efx->net_dev,
  1183. "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. netif_err(efx, probe, efx->net_dev,
  1192. "Falcon rev A0 not supported\n");
  1193. goto fail1;
  1194. }
  1195. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1196. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1197. netif_err(efx, probe, efx->net_dev,
  1198. "Falcon rev A1 1G not supported\n");
  1199. goto fail1;
  1200. }
  1201. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1202. netif_err(efx, probe, efx->net_dev,
  1203. "Falcon rev A1 PCI-X not supported\n");
  1204. goto fail1;
  1205. }
  1206. dev = pci_dev_get(efx->pci_dev);
  1207. while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
  1208. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
  1209. dev))) {
  1210. if (dev->bus == efx->pci_dev->bus &&
  1211. dev->devfn == efx->pci_dev->devfn + 1) {
  1212. nic_data->pci_dev2 = dev;
  1213. break;
  1214. }
  1215. }
  1216. if (!nic_data->pci_dev2) {
  1217. netif_err(efx, probe, efx->net_dev,
  1218. "failed to find secondary function\n");
  1219. rc = -ENODEV;
  1220. goto fail2;
  1221. }
  1222. }
  1223. /* Now we can reset the NIC */
  1224. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1225. if (rc) {
  1226. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1227. goto fail3;
  1228. }
  1229. /* Allocate memory for INT_KER */
  1230. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  1231. if (rc)
  1232. goto fail4;
  1233. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1234. netif_dbg(efx, probe, efx->net_dev,
  1235. "INT_KER at %llx (virt %p phys %llx)\n",
  1236. (u64)efx->irq_status.dma_addr,
  1237. efx->irq_status.addr,
  1238. (u64)virt_to_phys(efx->irq_status.addr));
  1239. falcon_probe_spi_devices(efx);
  1240. /* Read in the non-volatile configuration */
  1241. rc = falcon_probe_nvconfig(efx);
  1242. if (rc) {
  1243. if (rc == -EINVAL)
  1244. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1245. goto fail5;
  1246. }
  1247. efx->timer_quantum_ns = 4968; /* 621 cycles */
  1248. /* Initialise I2C adapter */
  1249. board = falcon_board(efx);
  1250. board->i2c_adap.owner = THIS_MODULE;
  1251. board->i2c_data = falcon_i2c_bit_operations;
  1252. board->i2c_data.data = efx;
  1253. board->i2c_adap.algo_data = &board->i2c_data;
  1254. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1255. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1256. sizeof(board->i2c_adap.name));
  1257. rc = i2c_bit_add_bus(&board->i2c_adap);
  1258. if (rc)
  1259. goto fail5;
  1260. rc = falcon_board(efx)->type->init(efx);
  1261. if (rc) {
  1262. netif_err(efx, probe, efx->net_dev,
  1263. "failed to initialise board\n");
  1264. goto fail6;
  1265. }
  1266. nic_data->stats_disable_count = 1;
  1267. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1268. (unsigned long)efx);
  1269. return 0;
  1270. fail6:
  1271. BUG_ON(i2c_del_adapter(&board->i2c_adap));
  1272. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1273. fail5:
  1274. efx_nic_free_buffer(efx, &efx->irq_status);
  1275. fail4:
  1276. fail3:
  1277. if (nic_data->pci_dev2) {
  1278. pci_dev_put(nic_data->pci_dev2);
  1279. nic_data->pci_dev2 = NULL;
  1280. }
  1281. fail2:
  1282. fail1:
  1283. kfree(efx->nic_data);
  1284. return rc;
  1285. }
  1286. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1287. {
  1288. /* Prior to Siena the RX DMA engine will split each frame at
  1289. * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
  1290. * be so large that that never happens. */
  1291. const unsigned huge_buf_size = (3 * 4096) >> 5;
  1292. /* RX control FIFO thresholds (32 entries) */
  1293. const unsigned ctrl_xon_thr = 20;
  1294. const unsigned ctrl_xoff_thr = 25;
  1295. efx_oword_t reg;
  1296. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1297. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1298. /* Data FIFO size is 5.5K */
  1299. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1300. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1301. huge_buf_size);
  1302. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  1303. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  1304. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1305. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1306. } else {
  1307. /* Data FIFO size is 80K; register fields moved */
  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. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  1312. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  1313. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  1314. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1315. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1316. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1317. /* Enable hash insertion. This is broken for the
  1318. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1319. * IPv4 hashes. */
  1320. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1321. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1322. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1323. }
  1324. /* Always enable XOFF signal from RX FIFO. We enable
  1325. * or disable transmission of pause frames at the MAC. */
  1326. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1327. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1328. }
  1329. /* This call performs hardware-specific global initialisation, such as
  1330. * defining the descriptor cache sizes and number of RSS channels.
  1331. * It does not set up any buffers, descriptor rings or event queues.
  1332. */
  1333. static int falcon_init_nic(struct efx_nic *efx)
  1334. {
  1335. efx_oword_t temp;
  1336. int rc;
  1337. /* Use on-chip SRAM */
  1338. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1339. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1340. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1341. rc = falcon_reset_sram(efx);
  1342. if (rc)
  1343. return rc;
  1344. /* Clear the parity enables on the TX data fifos as
  1345. * they produce false parity errors because of timing issues
  1346. */
  1347. if (EFX_WORKAROUND_5129(efx)) {
  1348. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1349. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1350. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1351. }
  1352. if (EFX_WORKAROUND_7244(efx)) {
  1353. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1354. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1355. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1356. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1357. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1358. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1359. }
  1360. /* XXX This is documented only for Falcon A0/A1 */
  1361. /* Setup RX. Wait for descriptor is broken and must
  1362. * be disabled. RXDP recovery shouldn't be needed, but is.
  1363. */
  1364. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1365. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1366. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1367. if (EFX_WORKAROUND_5583(efx))
  1368. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1369. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1370. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1371. * descriptors (which is bad).
  1372. */
  1373. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1374. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1375. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1376. falcon_init_rx_cfg(efx);
  1377. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1378. /* Set hash key for IPv4 */
  1379. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1380. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1381. /* Set destination of both TX and RX Flush events */
  1382. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1383. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1384. }
  1385. efx_nic_init_common(efx);
  1386. return 0;
  1387. }
  1388. static void falcon_remove_nic(struct efx_nic *efx)
  1389. {
  1390. struct falcon_nic_data *nic_data = efx->nic_data;
  1391. struct falcon_board *board = falcon_board(efx);
  1392. int rc;
  1393. board->type->fini(efx);
  1394. /* Remove I2C adapter and clear it in preparation for a retry */
  1395. rc = i2c_del_adapter(&board->i2c_adap);
  1396. BUG_ON(rc);
  1397. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1398. efx_nic_free_buffer(efx, &efx->irq_status);
  1399. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1400. /* Release the second function after the reset */
  1401. if (nic_data->pci_dev2) {
  1402. pci_dev_put(nic_data->pci_dev2);
  1403. nic_data->pci_dev2 = NULL;
  1404. }
  1405. /* Tear down the private nic state */
  1406. kfree(efx->nic_data);
  1407. efx->nic_data = NULL;
  1408. }
  1409. static void falcon_update_nic_stats(struct efx_nic *efx)
  1410. {
  1411. struct falcon_nic_data *nic_data = efx->nic_data;
  1412. efx_oword_t cnt;
  1413. if (nic_data->stats_disable_count)
  1414. return;
  1415. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1416. efx->n_rx_nodesc_drop_cnt +=
  1417. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1418. if (nic_data->stats_pending &&
  1419. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1420. nic_data->stats_pending = false;
  1421. rmb(); /* read the done flag before the stats */
  1422. falcon_update_stats_xmac(efx);
  1423. }
  1424. }
  1425. void falcon_start_nic_stats(struct efx_nic *efx)
  1426. {
  1427. struct falcon_nic_data *nic_data = efx->nic_data;
  1428. spin_lock_bh(&efx->stats_lock);
  1429. if (--nic_data->stats_disable_count == 0)
  1430. falcon_stats_request(efx);
  1431. spin_unlock_bh(&efx->stats_lock);
  1432. }
  1433. void falcon_stop_nic_stats(struct efx_nic *efx)
  1434. {
  1435. struct falcon_nic_data *nic_data = efx->nic_data;
  1436. int i;
  1437. might_sleep();
  1438. spin_lock_bh(&efx->stats_lock);
  1439. ++nic_data->stats_disable_count;
  1440. spin_unlock_bh(&efx->stats_lock);
  1441. del_timer_sync(&nic_data->stats_timer);
  1442. /* Wait enough time for the most recent transfer to
  1443. * complete. */
  1444. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1445. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1446. break;
  1447. msleep(1);
  1448. }
  1449. spin_lock_bh(&efx->stats_lock);
  1450. falcon_stats_complete(efx);
  1451. spin_unlock_bh(&efx->stats_lock);
  1452. }
  1453. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1454. {
  1455. falcon_board(efx)->type->set_id_led(efx, mode);
  1456. }
  1457. /**************************************************************************
  1458. *
  1459. * Wake on LAN
  1460. *
  1461. **************************************************************************
  1462. */
  1463. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1464. {
  1465. wol->supported = 0;
  1466. wol->wolopts = 0;
  1467. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1468. }
  1469. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1470. {
  1471. if (type != 0)
  1472. return -EINVAL;
  1473. return 0;
  1474. }
  1475. /**************************************************************************
  1476. *
  1477. * Revision-dependent attributes used by efx.c and nic.c
  1478. *
  1479. **************************************************************************
  1480. */
  1481. const struct efx_nic_type falcon_a1_nic_type = {
  1482. .probe = falcon_probe_nic,
  1483. .remove = falcon_remove_nic,
  1484. .init = falcon_init_nic,
  1485. .fini = efx_port_dummy_op_void,
  1486. .monitor = falcon_monitor,
  1487. .map_reset_reason = falcon_map_reset_reason,
  1488. .map_reset_flags = falcon_map_reset_flags,
  1489. .reset = falcon_reset_hw,
  1490. .probe_port = falcon_probe_port,
  1491. .remove_port = falcon_remove_port,
  1492. .handle_global_event = falcon_handle_global_event,
  1493. .prepare_flush = falcon_prepare_flush,
  1494. .update_stats = falcon_update_nic_stats,
  1495. .start_stats = falcon_start_nic_stats,
  1496. .stop_stats = falcon_stop_nic_stats,
  1497. .set_id_led = falcon_set_id_led,
  1498. .push_irq_moderation = falcon_push_irq_moderation,
  1499. .reconfigure_port = falcon_reconfigure_port,
  1500. .reconfigure_mac = falcon_reconfigure_xmac,
  1501. .check_mac_fault = falcon_xmac_check_fault,
  1502. .get_wol = falcon_get_wol,
  1503. .set_wol = falcon_set_wol,
  1504. .resume_wol = efx_port_dummy_op_void,
  1505. .test_nvram = falcon_test_nvram,
  1506. .revision = EFX_REV_FALCON_A1,
  1507. .mem_map_size = 0x20000,
  1508. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  1509. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  1510. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  1511. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  1512. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  1513. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1514. .rx_buffer_padding = 0x24,
  1515. .max_interrupt_mode = EFX_INT_MODE_MSI,
  1516. .phys_addr_channels = 4,
  1517. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  1518. .tx_dc_base = 0x130000,
  1519. .rx_dc_base = 0x100000,
  1520. .offload_features = NETIF_F_IP_CSUM,
  1521. };
  1522. const struct efx_nic_type falcon_b0_nic_type = {
  1523. .probe = falcon_probe_nic,
  1524. .remove = falcon_remove_nic,
  1525. .init = falcon_init_nic,
  1526. .fini = efx_port_dummy_op_void,
  1527. .monitor = falcon_monitor,
  1528. .map_reset_reason = falcon_map_reset_reason,
  1529. .map_reset_flags = falcon_map_reset_flags,
  1530. .reset = falcon_reset_hw,
  1531. .probe_port = falcon_probe_port,
  1532. .remove_port = falcon_remove_port,
  1533. .handle_global_event = falcon_handle_global_event,
  1534. .prepare_flush = falcon_prepare_flush,
  1535. .update_stats = falcon_update_nic_stats,
  1536. .start_stats = falcon_start_nic_stats,
  1537. .stop_stats = falcon_stop_nic_stats,
  1538. .set_id_led = falcon_set_id_led,
  1539. .push_irq_moderation = falcon_push_irq_moderation,
  1540. .reconfigure_port = falcon_reconfigure_port,
  1541. .reconfigure_mac = falcon_reconfigure_xmac,
  1542. .check_mac_fault = falcon_xmac_check_fault,
  1543. .get_wol = falcon_get_wol,
  1544. .set_wol = falcon_set_wol,
  1545. .resume_wol = efx_port_dummy_op_void,
  1546. .test_registers = falcon_b0_test_registers,
  1547. .test_nvram = falcon_test_nvram,
  1548. .revision = EFX_REV_FALCON_B0,
  1549. /* Map everything up to and including the RSS indirection
  1550. * table. Don't map MSI-X table, MSI-X PBA since Linux
  1551. * requires that they not be mapped. */
  1552. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  1553. FR_BZ_RX_INDIRECTION_TBL_STEP *
  1554. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  1555. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  1556. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  1557. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  1558. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  1559. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  1560. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  1561. .rx_buffer_hash_size = 0x10,
  1562. .rx_buffer_padding = 0,
  1563. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  1564. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  1565. * interrupt handler only supports 32
  1566. * channels */
  1567. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  1568. .tx_dc_base = 0x130000,
  1569. .rx_dc_base = 0x100000,
  1570. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  1571. };