ar8327.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. * ar8327.c: AR8216 switch driver
  3. *
  4. * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
  5. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/list.h>
  18. #include <linux/bitops.h>
  19. #include <linux/switch.h>
  20. #include <linux/delay.h>
  21. #include <linux/phy.h>
  22. #include <linux/lockdep.h>
  23. #include <linux/ar8216_platform.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/of_device.h>
  26. #include <linux/leds.h>
  27. #include <linux/mdio.h>
  28. #include "ar8216.h"
  29. #include "ar8327.h"
  30. extern const struct ar8xxx_mib_desc ar8236_mibs[39];
  31. extern const struct switch_attr ar8xxx_sw_attr_vlan[1];
  32. static u32
  33. ar8327_get_pad_cfg(struct ar8327_pad_cfg *cfg)
  34. {
  35. u32 t;
  36. if (!cfg)
  37. return 0;
  38. t = 0;
  39. switch (cfg->mode) {
  40. case AR8327_PAD_NC:
  41. break;
  42. case AR8327_PAD_MAC2MAC_MII:
  43. t = AR8327_PAD_MAC_MII_EN;
  44. if (cfg->rxclk_sel)
  45. t |= AR8327_PAD_MAC_MII_RXCLK_SEL;
  46. if (cfg->txclk_sel)
  47. t |= AR8327_PAD_MAC_MII_TXCLK_SEL;
  48. break;
  49. case AR8327_PAD_MAC2MAC_GMII:
  50. t = AR8327_PAD_MAC_GMII_EN;
  51. if (cfg->rxclk_sel)
  52. t |= AR8327_PAD_MAC_GMII_RXCLK_SEL;
  53. if (cfg->txclk_sel)
  54. t |= AR8327_PAD_MAC_GMII_TXCLK_SEL;
  55. break;
  56. case AR8327_PAD_MAC_SGMII:
  57. t = AR8327_PAD_SGMII_EN;
  58. /*
  59. * WAR for the QUalcomm Atheros AP136 board.
  60. * It seems that RGMII TX/RX delay settings needs to be
  61. * applied for SGMII mode as well, The ethernet is not
  62. * reliable without this.
  63. */
  64. t |= cfg->txclk_delay_sel << AR8327_PAD_RGMII_TXCLK_DELAY_SEL_S;
  65. t |= cfg->rxclk_delay_sel << AR8327_PAD_RGMII_RXCLK_DELAY_SEL_S;
  66. if (cfg->rxclk_delay_en)
  67. t |= AR8327_PAD_RGMII_RXCLK_DELAY_EN;
  68. if (cfg->txclk_delay_en)
  69. t |= AR8327_PAD_RGMII_TXCLK_DELAY_EN;
  70. if (cfg->sgmii_delay_en)
  71. t |= AR8327_PAD_SGMII_DELAY_EN;
  72. break;
  73. case AR8327_PAD_MAC2PHY_MII:
  74. t = AR8327_PAD_PHY_MII_EN;
  75. if (cfg->rxclk_sel)
  76. t |= AR8327_PAD_PHY_MII_RXCLK_SEL;
  77. if (cfg->txclk_sel)
  78. t |= AR8327_PAD_PHY_MII_TXCLK_SEL;
  79. break;
  80. case AR8327_PAD_MAC2PHY_GMII:
  81. t = AR8327_PAD_PHY_GMII_EN;
  82. if (cfg->pipe_rxclk_sel)
  83. t |= AR8327_PAD_PHY_GMII_PIPE_RXCLK_SEL;
  84. if (cfg->rxclk_sel)
  85. t |= AR8327_PAD_PHY_GMII_RXCLK_SEL;
  86. if (cfg->txclk_sel)
  87. t |= AR8327_PAD_PHY_GMII_TXCLK_SEL;
  88. break;
  89. case AR8327_PAD_MAC_RGMII:
  90. t = AR8327_PAD_RGMII_EN;
  91. t |= cfg->txclk_delay_sel << AR8327_PAD_RGMII_TXCLK_DELAY_SEL_S;
  92. t |= cfg->rxclk_delay_sel << AR8327_PAD_RGMII_RXCLK_DELAY_SEL_S;
  93. if (cfg->rxclk_delay_en)
  94. t |= AR8327_PAD_RGMII_RXCLK_DELAY_EN;
  95. if (cfg->txclk_delay_en)
  96. t |= AR8327_PAD_RGMII_TXCLK_DELAY_EN;
  97. break;
  98. case AR8327_PAD_PHY_GMII:
  99. t = AR8327_PAD_PHYX_GMII_EN;
  100. break;
  101. case AR8327_PAD_PHY_RGMII:
  102. t = AR8327_PAD_PHYX_RGMII_EN;
  103. break;
  104. case AR8327_PAD_PHY_MII:
  105. t = AR8327_PAD_PHYX_MII_EN;
  106. break;
  107. }
  108. if (cfg->mac06_exchange_en)
  109. t |= AR8337_PAD_MAC06_EXCHANGE_EN;
  110. return t;
  111. }
  112. static void
  113. ar8327_phy_fixup(struct ar8xxx_priv *priv, int phy)
  114. {
  115. switch (priv->chip_rev) {
  116. case 1:
  117. /* For 100M waveform */
  118. ar8xxx_phy_dbg_write(priv, phy, 0, 0x02ea);
  119. /* Turn on Gigabit clock */
  120. ar8xxx_phy_dbg_write(priv, phy, 0x3d, 0x68a0);
  121. break;
  122. case 2:
  123. ar8xxx_phy_mmd_write(priv, phy, 0x7, 0x3c);
  124. ar8xxx_phy_mmd_write(priv, phy, 0x4007, 0x0);
  125. /* fallthrough */
  126. case 4:
  127. ar8xxx_phy_mmd_write(priv, phy, 0x3, 0x800d);
  128. ar8xxx_phy_mmd_write(priv, phy, 0x4003, 0x803f);
  129. ar8xxx_phy_dbg_write(priv, phy, 0x3d, 0x6860);
  130. ar8xxx_phy_dbg_write(priv, phy, 0x5, 0x2c46);
  131. ar8xxx_phy_dbg_write(priv, phy, 0x3c, 0x6000);
  132. break;
  133. }
  134. }
  135. static u32
  136. ar8327_get_port_init_status(struct ar8327_port_cfg *cfg)
  137. {
  138. u32 t;
  139. if (!cfg->force_link)
  140. return AR8216_PORT_STATUS_LINK_AUTO;
  141. t = AR8216_PORT_STATUS_TXMAC | AR8216_PORT_STATUS_RXMAC;
  142. t |= cfg->duplex ? AR8216_PORT_STATUS_DUPLEX : 0;
  143. t |= cfg->rxpause ? AR8216_PORT_STATUS_RXFLOW : 0;
  144. t |= cfg->txpause ? AR8216_PORT_STATUS_TXFLOW : 0;
  145. switch (cfg->speed) {
  146. case AR8327_PORT_SPEED_10:
  147. t |= AR8216_PORT_SPEED_10M;
  148. break;
  149. case AR8327_PORT_SPEED_100:
  150. t |= AR8216_PORT_SPEED_100M;
  151. break;
  152. case AR8327_PORT_SPEED_1000:
  153. t |= AR8216_PORT_SPEED_1000M;
  154. break;
  155. }
  156. return t;
  157. }
  158. #define AR8327_LED_ENTRY(_num, _reg, _shift) \
  159. [_num] = { .reg = (_reg), .shift = (_shift) }
  160. static const struct ar8327_led_entry
  161. ar8327_led_map[AR8327_NUM_LEDS] = {
  162. AR8327_LED_ENTRY(AR8327_LED_PHY0_0, 0, 14),
  163. AR8327_LED_ENTRY(AR8327_LED_PHY0_1, 1, 14),
  164. AR8327_LED_ENTRY(AR8327_LED_PHY0_2, 2, 14),
  165. AR8327_LED_ENTRY(AR8327_LED_PHY1_0, 3, 8),
  166. AR8327_LED_ENTRY(AR8327_LED_PHY1_1, 3, 10),
  167. AR8327_LED_ENTRY(AR8327_LED_PHY1_2, 3, 12),
  168. AR8327_LED_ENTRY(AR8327_LED_PHY2_0, 3, 14),
  169. AR8327_LED_ENTRY(AR8327_LED_PHY2_1, 3, 16),
  170. AR8327_LED_ENTRY(AR8327_LED_PHY2_2, 3, 18),
  171. AR8327_LED_ENTRY(AR8327_LED_PHY3_0, 3, 20),
  172. AR8327_LED_ENTRY(AR8327_LED_PHY3_1, 3, 22),
  173. AR8327_LED_ENTRY(AR8327_LED_PHY3_2, 3, 24),
  174. AR8327_LED_ENTRY(AR8327_LED_PHY4_0, 0, 30),
  175. AR8327_LED_ENTRY(AR8327_LED_PHY4_1, 1, 30),
  176. AR8327_LED_ENTRY(AR8327_LED_PHY4_2, 2, 30),
  177. };
  178. static void
  179. ar8327_set_led_pattern(struct ar8xxx_priv *priv, unsigned int led_num,
  180. enum ar8327_led_pattern pattern)
  181. {
  182. const struct ar8327_led_entry *entry;
  183. entry = &ar8327_led_map[led_num];
  184. ar8xxx_rmw(priv, AR8327_REG_LED_CTRL(entry->reg),
  185. (3 << entry->shift), pattern << entry->shift);
  186. }
  187. static void
  188. ar8327_led_work_func(struct work_struct *work)
  189. {
  190. struct ar8327_led *aled;
  191. u8 pattern;
  192. aled = container_of(work, struct ar8327_led, led_work);
  193. spin_lock(&aled->lock);
  194. pattern = aled->pattern;
  195. spin_unlock(&aled->lock);
  196. ar8327_set_led_pattern(aled->sw_priv, aled->led_num,
  197. pattern);
  198. }
  199. static void
  200. ar8327_led_schedule_change(struct ar8327_led *aled, u8 pattern)
  201. {
  202. if (aled->pattern == pattern)
  203. return;
  204. aled->pattern = pattern;
  205. schedule_work(&aled->led_work);
  206. }
  207. static inline struct ar8327_led *
  208. led_cdev_to_ar8327_led(struct led_classdev *led_cdev)
  209. {
  210. return container_of(led_cdev, struct ar8327_led, cdev);
  211. }
  212. static int
  213. ar8327_led_blink_set(struct led_classdev *led_cdev,
  214. unsigned long *delay_on,
  215. unsigned long *delay_off)
  216. {
  217. struct ar8327_led *aled = led_cdev_to_ar8327_led(led_cdev);
  218. if (*delay_on == 0 && *delay_off == 0) {
  219. *delay_on = 125;
  220. *delay_off = 125;
  221. }
  222. if (*delay_on != 125 || *delay_off != 125) {
  223. /*
  224. * The hardware only supports blinking at 4Hz. Fall back
  225. * to software implementation in other cases.
  226. */
  227. return -EINVAL;
  228. }
  229. spin_lock(&aled->lock);
  230. aled->enable_hw_mode = false;
  231. ar8327_led_schedule_change(aled, AR8327_LED_PATTERN_BLINK);
  232. spin_unlock(&aled->lock);
  233. return 0;
  234. }
  235. static void
  236. ar8327_led_set_brightness(struct led_classdev *led_cdev,
  237. enum led_brightness brightness)
  238. {
  239. struct ar8327_led *aled = led_cdev_to_ar8327_led(led_cdev);
  240. u8 pattern;
  241. bool active;
  242. active = (brightness != LED_OFF);
  243. active ^= aled->active_low;
  244. pattern = (active) ? AR8327_LED_PATTERN_ON :
  245. AR8327_LED_PATTERN_OFF;
  246. spin_lock(&aled->lock);
  247. aled->enable_hw_mode = false;
  248. ar8327_led_schedule_change(aled, pattern);
  249. spin_unlock(&aled->lock);
  250. }
  251. static ssize_t
  252. ar8327_led_enable_hw_mode_show(struct device *dev,
  253. struct device_attribute *attr,
  254. char *buf)
  255. {
  256. struct led_classdev *led_cdev = dev_get_drvdata(dev);
  257. struct ar8327_led *aled = led_cdev_to_ar8327_led(led_cdev);
  258. ssize_t ret = 0;
  259. spin_lock(&aled->lock);
  260. ret += sprintf(buf, "%d\n", aled->enable_hw_mode);
  261. spin_unlock(&aled->lock);
  262. return ret;
  263. }
  264. static ssize_t
  265. ar8327_led_enable_hw_mode_store(struct device *dev,
  266. struct device_attribute *attr,
  267. const char *buf,
  268. size_t size)
  269. {
  270. struct led_classdev *led_cdev = dev_get_drvdata(dev);
  271. struct ar8327_led *aled = led_cdev_to_ar8327_led(led_cdev);
  272. u8 pattern;
  273. u8 value;
  274. int ret;
  275. ret = kstrtou8(buf, 10, &value);
  276. if (ret < 0)
  277. return -EINVAL;
  278. spin_lock(&aled->lock);
  279. aled->enable_hw_mode = !!value;
  280. if (aled->enable_hw_mode)
  281. pattern = AR8327_LED_PATTERN_RULE;
  282. else
  283. pattern = AR8327_LED_PATTERN_OFF;
  284. ar8327_led_schedule_change(aled, pattern);
  285. spin_unlock(&aled->lock);
  286. return size;
  287. }
  288. static DEVICE_ATTR(enable_hw_mode, S_IRUGO | S_IWUSR,
  289. ar8327_led_enable_hw_mode_show,
  290. ar8327_led_enable_hw_mode_store);
  291. static int
  292. ar8327_led_register(struct ar8327_led *aled)
  293. {
  294. int ret;
  295. ret = led_classdev_register(NULL, &aled->cdev);
  296. if (ret < 0)
  297. return ret;
  298. if (aled->mode == AR8327_LED_MODE_HW) {
  299. ret = device_create_file(aled->cdev.dev,
  300. &dev_attr_enable_hw_mode);
  301. if (ret)
  302. goto err_unregister;
  303. }
  304. return 0;
  305. err_unregister:
  306. led_classdev_unregister(&aled->cdev);
  307. return ret;
  308. }
  309. static void
  310. ar8327_led_unregister(struct ar8327_led *aled)
  311. {
  312. if (aled->mode == AR8327_LED_MODE_HW)
  313. device_remove_file(aled->cdev.dev, &dev_attr_enable_hw_mode);
  314. led_classdev_unregister(&aled->cdev);
  315. cancel_work_sync(&aled->led_work);
  316. }
  317. static int
  318. ar8327_led_create(struct ar8xxx_priv *priv,
  319. const struct ar8327_led_info *led_info)
  320. {
  321. struct ar8327_data *data = priv->chip_data;
  322. struct ar8327_led *aled;
  323. int ret;
  324. if (!IS_ENABLED(CONFIG_AR8216_PHY_LEDS))
  325. return 0;
  326. if (!led_info->name)
  327. return -EINVAL;
  328. if (led_info->led_num >= AR8327_NUM_LEDS)
  329. return -EINVAL;
  330. aled = kzalloc(sizeof(*aled) + strlen(led_info->name) + 1,
  331. GFP_KERNEL);
  332. if (!aled)
  333. return -ENOMEM;
  334. aled->sw_priv = priv;
  335. aled->led_num = led_info->led_num;
  336. aled->active_low = led_info->active_low;
  337. aled->mode = led_info->mode;
  338. if (aled->mode == AR8327_LED_MODE_HW)
  339. aled->enable_hw_mode = true;
  340. aled->name = (char *)(aled + 1);
  341. strcpy(aled->name, led_info->name);
  342. aled->cdev.name = aled->name;
  343. aled->cdev.brightness_set = ar8327_led_set_brightness;
  344. aled->cdev.blink_set = ar8327_led_blink_set;
  345. aled->cdev.default_trigger = led_info->default_trigger;
  346. spin_lock_init(&aled->lock);
  347. mutex_init(&aled->mutex);
  348. INIT_WORK(&aled->led_work, ar8327_led_work_func);
  349. ret = ar8327_led_register(aled);
  350. if (ret)
  351. goto err_free;
  352. data->leds[data->num_leds++] = aled;
  353. return 0;
  354. err_free:
  355. kfree(aled);
  356. return ret;
  357. }
  358. static void
  359. ar8327_led_destroy(struct ar8327_led *aled)
  360. {
  361. ar8327_led_unregister(aled);
  362. kfree(aled);
  363. }
  364. static void
  365. ar8327_leds_init(struct ar8xxx_priv *priv)
  366. {
  367. struct ar8327_data *data = priv->chip_data;
  368. unsigned i;
  369. if (!IS_ENABLED(CONFIG_AR8216_PHY_LEDS))
  370. return;
  371. for (i = 0; i < data->num_leds; i++) {
  372. struct ar8327_led *aled;
  373. aled = data->leds[i];
  374. if (aled->enable_hw_mode)
  375. aled->pattern = AR8327_LED_PATTERN_RULE;
  376. else
  377. aled->pattern = AR8327_LED_PATTERN_OFF;
  378. ar8327_set_led_pattern(priv, aled->led_num, aled->pattern);
  379. }
  380. }
  381. static void
  382. ar8327_leds_cleanup(struct ar8xxx_priv *priv)
  383. {
  384. struct ar8327_data *data = priv->chip_data;
  385. unsigned i;
  386. if (!IS_ENABLED(CONFIG_AR8216_PHY_LEDS))
  387. return;
  388. for (i = 0; i < data->num_leds; i++) {
  389. struct ar8327_led *aled;
  390. aled = data->leds[i];
  391. ar8327_led_destroy(aled);
  392. }
  393. kfree(data->leds);
  394. }
  395. static int
  396. ar8327_hw_config_pdata(struct ar8xxx_priv *priv,
  397. struct ar8327_platform_data *pdata)
  398. {
  399. struct ar8327_led_cfg *led_cfg;
  400. struct ar8327_data *data = priv->chip_data;
  401. u32 pos, new_pos;
  402. u32 t;
  403. if (!pdata)
  404. return -EINVAL;
  405. priv->get_port_link = pdata->get_port_link;
  406. data->port0_status = ar8327_get_port_init_status(&pdata->port0_cfg);
  407. data->port6_status = ar8327_get_port_init_status(&pdata->port6_cfg);
  408. t = ar8327_get_pad_cfg(pdata->pad0_cfg);
  409. ar8xxx_write(priv, AR8327_REG_PAD0_MODE, t);
  410. t = ar8327_get_pad_cfg(pdata->pad5_cfg);
  411. ar8xxx_write(priv, AR8327_REG_PAD5_MODE, t);
  412. t = ar8327_get_pad_cfg(pdata->pad6_cfg);
  413. ar8xxx_write(priv, AR8327_REG_PAD6_MODE, t);
  414. pos = ar8xxx_read(priv, AR8327_REG_POWER_ON_STRIP);
  415. new_pos = pos;
  416. led_cfg = pdata->led_cfg;
  417. if (led_cfg) {
  418. if (led_cfg->open_drain)
  419. new_pos |= AR8327_POWER_ON_STRIP_LED_OPEN_EN;
  420. else
  421. new_pos &= ~AR8327_POWER_ON_STRIP_LED_OPEN_EN;
  422. ar8xxx_write(priv, AR8327_REG_LED_CTRL0, led_cfg->led_ctrl0);
  423. ar8xxx_write(priv, AR8327_REG_LED_CTRL1, led_cfg->led_ctrl1);
  424. ar8xxx_write(priv, AR8327_REG_LED_CTRL2, led_cfg->led_ctrl2);
  425. ar8xxx_write(priv, AR8327_REG_LED_CTRL3, led_cfg->led_ctrl3);
  426. if (new_pos != pos)
  427. new_pos |= AR8327_POWER_ON_STRIP_POWER_ON_SEL;
  428. }
  429. if (pdata->sgmii_cfg) {
  430. t = pdata->sgmii_cfg->sgmii_ctrl;
  431. if (priv->chip_rev == 1)
  432. t |= AR8327_SGMII_CTRL_EN_PLL |
  433. AR8327_SGMII_CTRL_EN_RX |
  434. AR8327_SGMII_CTRL_EN_TX;
  435. else
  436. t &= ~(AR8327_SGMII_CTRL_EN_PLL |
  437. AR8327_SGMII_CTRL_EN_RX |
  438. AR8327_SGMII_CTRL_EN_TX);
  439. ar8xxx_write(priv, AR8327_REG_SGMII_CTRL, t);
  440. if (pdata->sgmii_cfg->serdes_aen)
  441. new_pos &= ~AR8327_POWER_ON_STRIP_SERDES_AEN;
  442. else
  443. new_pos |= AR8327_POWER_ON_STRIP_SERDES_AEN;
  444. }
  445. ar8xxx_write(priv, AR8327_REG_POWER_ON_STRIP, new_pos);
  446. if (pdata->leds && pdata->num_leds) {
  447. int i;
  448. data->leds = kzalloc(pdata->num_leds * sizeof(void *),
  449. GFP_KERNEL);
  450. if (!data->leds)
  451. return -ENOMEM;
  452. for (i = 0; i < pdata->num_leds; i++)
  453. ar8327_led_create(priv, &pdata->leds[i]);
  454. }
  455. return 0;
  456. }
  457. #ifdef CONFIG_OF
  458. static int
  459. ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
  460. {
  461. struct ar8327_data *data = priv->chip_data;
  462. const __be32 *paddr;
  463. int len;
  464. int i;
  465. paddr = of_get_property(np, "qca,ar8327-initvals", &len);
  466. if (!paddr || len < (2 * sizeof(*paddr)))
  467. return -EINVAL;
  468. len /= sizeof(*paddr);
  469. for (i = 0; i < len - 1; i += 2) {
  470. u32 reg;
  471. u32 val;
  472. reg = be32_to_cpup(paddr + i);
  473. val = be32_to_cpup(paddr + i + 1);
  474. switch (reg) {
  475. case AR8327_REG_PORT_STATUS(0):
  476. data->port0_status = val;
  477. break;
  478. case AR8327_REG_PORT_STATUS(6):
  479. data->port6_status = val;
  480. break;
  481. default:
  482. ar8xxx_write(priv, reg, val);
  483. break;
  484. }
  485. }
  486. return 0;
  487. }
  488. #else
  489. static inline int
  490. ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
  491. {
  492. return -EINVAL;
  493. }
  494. #endif
  495. static int
  496. ar8327_hw_init(struct ar8xxx_priv *priv)
  497. {
  498. int ret;
  499. priv->chip_data = kzalloc(sizeof(struct ar8327_data), GFP_KERNEL);
  500. if (!priv->chip_data)
  501. return -ENOMEM;
  502. if (priv->phy->dev.of_node)
  503. ret = ar8327_hw_config_of(priv, priv->phy->dev.of_node);
  504. else
  505. ret = ar8327_hw_config_pdata(priv,
  506. priv->phy->dev.platform_data);
  507. if (ret)
  508. return ret;
  509. ar8327_leds_init(priv);
  510. ar8xxx_phy_init(priv);
  511. return 0;
  512. }
  513. static void
  514. ar8327_cleanup(struct ar8xxx_priv *priv)
  515. {
  516. ar8327_leds_cleanup(priv);
  517. }
  518. static void
  519. ar8327_init_globals(struct ar8xxx_priv *priv)
  520. {
  521. struct ar8327_data *data = priv->chip_data;
  522. u32 t;
  523. int i;
  524. /* enable CPU port and disable mirror port */
  525. t = AR8327_FWD_CTRL0_CPU_PORT_EN |
  526. AR8327_FWD_CTRL0_MIRROR_PORT;
  527. ar8xxx_write(priv, AR8327_REG_FWD_CTRL0, t);
  528. /* forward multicast and broadcast frames to CPU */
  529. t = (AR8327_PORTS_ALL << AR8327_FWD_CTRL1_UC_FLOOD_S) |
  530. (AR8327_PORTS_ALL << AR8327_FWD_CTRL1_MC_FLOOD_S) |
  531. (AR8327_PORTS_ALL << AR8327_FWD_CTRL1_BC_FLOOD_S);
  532. ar8xxx_write(priv, AR8327_REG_FWD_CTRL1, t);
  533. /* enable jumbo frames */
  534. ar8xxx_rmw(priv, AR8327_REG_MAX_FRAME_SIZE,
  535. AR8327_MAX_FRAME_SIZE_MTU, 9018 + 8 + 2);
  536. /* Enable MIB counters */
  537. ar8xxx_reg_set(priv, AR8327_REG_MODULE_EN,
  538. AR8327_MODULE_EN_MIB);
  539. /* Disable EEE on all phy's due to stability issues */
  540. for (i = 0; i < AR8XXX_NUM_PHYS; i++)
  541. data->eee[i] = false;
  542. }
  543. static void
  544. ar8327_init_port(struct ar8xxx_priv *priv, int port)
  545. {
  546. struct ar8327_data *data = priv->chip_data;
  547. u32 t;
  548. if (port == AR8216_PORT_CPU)
  549. t = data->port0_status;
  550. else if (port == 6)
  551. t = data->port6_status;
  552. else
  553. t = AR8216_PORT_STATUS_LINK_AUTO;
  554. ar8xxx_write(priv, AR8327_REG_PORT_STATUS(port), t);
  555. ar8xxx_write(priv, AR8327_REG_PORT_HEADER(port), 0);
  556. t = 1 << AR8327_PORT_VLAN0_DEF_SVID_S;
  557. t |= 1 << AR8327_PORT_VLAN0_DEF_CVID_S;
  558. ar8xxx_write(priv, AR8327_REG_PORT_VLAN0(port), t);
  559. t = AR8327_PORT_VLAN1_OUT_MODE_UNTOUCH << AR8327_PORT_VLAN1_OUT_MODE_S;
  560. ar8xxx_write(priv, AR8327_REG_PORT_VLAN1(port), t);
  561. t = AR8327_PORT_LOOKUP_LEARN;
  562. t |= AR8216_PORT_STATE_FORWARD << AR8327_PORT_LOOKUP_STATE_S;
  563. ar8xxx_write(priv, AR8327_REG_PORT_LOOKUP(port), t);
  564. }
  565. static u32
  566. ar8327_read_port_status(struct ar8xxx_priv *priv, int port)
  567. {
  568. u32 t;
  569. t = ar8xxx_read(priv, AR8327_REG_PORT_STATUS(port));
  570. /* map the flow control autoneg result bits to the flow control bits
  571. * used in forced mode to allow ar8216_read_port_link detect
  572. * flow control properly if autoneg is used
  573. */
  574. if (t & AR8216_PORT_STATUS_LINK_UP &&
  575. t & AR8216_PORT_STATUS_LINK_AUTO) {
  576. t &= ~(AR8216_PORT_STATUS_TXFLOW | AR8216_PORT_STATUS_RXFLOW);
  577. if (t & AR8327_PORT_STATUS_TXFLOW_AUTO)
  578. t |= AR8216_PORT_STATUS_TXFLOW;
  579. if (t & AR8327_PORT_STATUS_RXFLOW_AUTO)
  580. t |= AR8216_PORT_STATUS_RXFLOW;
  581. }
  582. return t;
  583. }
  584. static u32
  585. ar8327_read_port_eee_status(struct ar8xxx_priv *priv, int port)
  586. {
  587. int phy;
  588. u16 t;
  589. if (port >= priv->dev.ports)
  590. return 0;
  591. if (port == 0 || port == 6)
  592. return 0;
  593. phy = port - 1;
  594. /* EEE Ability Auto-negotiation Result */
  595. ar8xxx_phy_mmd_write(priv, phy, 0x7, 0x8000);
  596. t = ar8xxx_phy_mmd_read(priv, phy, 0x4007);
  597. return mmd_eee_adv_to_ethtool_adv_t(t);
  598. }
  599. static int
  600. ar8327_atu_flush(struct ar8xxx_priv *priv)
  601. {
  602. int ret;
  603. ret = ar8216_wait_bit(priv, AR8327_REG_ATU_FUNC,
  604. AR8327_ATU_FUNC_BUSY, 0);
  605. if (!ret)
  606. ar8xxx_write(priv, AR8327_REG_ATU_FUNC,
  607. AR8327_ATU_FUNC_OP_FLUSH |
  608. AR8327_ATU_FUNC_BUSY);
  609. return ret;
  610. }
  611. static void
  612. ar8327_vtu_op(struct ar8xxx_priv *priv, u32 op, u32 val)
  613. {
  614. if (ar8216_wait_bit(priv, AR8327_REG_VTU_FUNC1,
  615. AR8327_VTU_FUNC1_BUSY, 0))
  616. return;
  617. if ((op & AR8327_VTU_FUNC1_OP) == AR8327_VTU_FUNC1_OP_LOAD)
  618. ar8xxx_write(priv, AR8327_REG_VTU_FUNC0, val);
  619. op |= AR8327_VTU_FUNC1_BUSY;
  620. ar8xxx_write(priv, AR8327_REG_VTU_FUNC1, op);
  621. }
  622. static void
  623. ar8327_vtu_flush(struct ar8xxx_priv *priv)
  624. {
  625. ar8327_vtu_op(priv, AR8327_VTU_FUNC1_OP_FLUSH, 0);
  626. }
  627. static void
  628. ar8327_vtu_load_vlan(struct ar8xxx_priv *priv, u32 vid, u32 port_mask)
  629. {
  630. u32 op;
  631. u32 val;
  632. int i;
  633. op = AR8327_VTU_FUNC1_OP_LOAD | (vid << AR8327_VTU_FUNC1_VID_S);
  634. val = AR8327_VTU_FUNC0_VALID | AR8327_VTU_FUNC0_IVL;
  635. for (i = 0; i < AR8327_NUM_PORTS; i++) {
  636. u32 mode;
  637. if ((port_mask & BIT(i)) == 0)
  638. mode = AR8327_VTU_FUNC0_EG_MODE_NOT;
  639. else if (priv->vlan == 0)
  640. mode = AR8327_VTU_FUNC0_EG_MODE_KEEP;
  641. else if ((priv->vlan_tagged & BIT(i)) || (priv->vlan_id[priv->pvid[i]] != vid))
  642. mode = AR8327_VTU_FUNC0_EG_MODE_TAG;
  643. else
  644. mode = AR8327_VTU_FUNC0_EG_MODE_UNTAG;
  645. val |= mode << AR8327_VTU_FUNC0_EG_MODE_S(i);
  646. }
  647. ar8327_vtu_op(priv, op, val);
  648. }
  649. static void
  650. ar8327_setup_port(struct ar8xxx_priv *priv, int port, u32 members)
  651. {
  652. u32 t;
  653. u32 egress, ingress;
  654. u32 pvid = priv->vlan_id[priv->pvid[port]];
  655. if (priv->vlan) {
  656. egress = AR8327_PORT_VLAN1_OUT_MODE_UNMOD;
  657. ingress = AR8216_IN_SECURE;
  658. } else {
  659. egress = AR8327_PORT_VLAN1_OUT_MODE_UNTOUCH;
  660. ingress = AR8216_IN_PORT_ONLY;
  661. }
  662. t = pvid << AR8327_PORT_VLAN0_DEF_SVID_S;
  663. t |= pvid << AR8327_PORT_VLAN0_DEF_CVID_S;
  664. ar8xxx_write(priv, AR8327_REG_PORT_VLAN0(port), t);
  665. t = AR8327_PORT_VLAN1_PORT_VLAN_PROP;
  666. t |= egress << AR8327_PORT_VLAN1_OUT_MODE_S;
  667. ar8xxx_write(priv, AR8327_REG_PORT_VLAN1(port), t);
  668. t = members;
  669. t |= AR8327_PORT_LOOKUP_LEARN;
  670. t |= ingress << AR8327_PORT_LOOKUP_IN_MODE_S;
  671. t |= AR8216_PORT_STATE_FORWARD << AR8327_PORT_LOOKUP_STATE_S;
  672. ar8xxx_write(priv, AR8327_REG_PORT_LOOKUP(port), t);
  673. }
  674. static int
  675. ar8327_sw_get_ports(struct switch_dev *dev, struct switch_val *val)
  676. {
  677. struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
  678. u8 ports = priv->vlan_table[val->port_vlan];
  679. int i;
  680. val->len = 0;
  681. for (i = 0; i < dev->ports; i++) {
  682. struct switch_port *p;
  683. if (!(ports & (1 << i)))
  684. continue;
  685. p = &val->value.ports[val->len++];
  686. p->id = i;
  687. if ((priv->vlan_tagged & (1 << i)) || (priv->pvid[i] != val->port_vlan))
  688. p->flags = (1 << SWITCH_PORT_FLAG_TAGGED);
  689. else
  690. p->flags = 0;
  691. }
  692. return 0;
  693. }
  694. static int
  695. ar8327_sw_set_ports(struct switch_dev *dev, struct switch_val *val)
  696. {
  697. struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
  698. u8 *vt = &priv->vlan_table[val->port_vlan];
  699. int i;
  700. *vt = 0;
  701. for (i = 0; i < val->len; i++) {
  702. struct switch_port *p = &val->value.ports[i];
  703. if (p->flags & (1 << SWITCH_PORT_FLAG_TAGGED)) {
  704. if (val->port_vlan == priv->pvid[p->id]) {
  705. priv->vlan_tagged |= (1 << p->id);
  706. }
  707. } else {
  708. priv->vlan_tagged &= ~(1 << p->id);
  709. priv->pvid[p->id] = val->port_vlan;
  710. }
  711. *vt |= 1 << p->id;
  712. }
  713. return 0;
  714. }
  715. static void
  716. ar8327_set_mirror_regs(struct ar8xxx_priv *priv)
  717. {
  718. int port;
  719. /* reset all mirror registers */
  720. ar8xxx_rmw(priv, AR8327_REG_FWD_CTRL0,
  721. AR8327_FWD_CTRL0_MIRROR_PORT,
  722. (0xF << AR8327_FWD_CTRL0_MIRROR_PORT_S));
  723. for (port = 0; port < AR8327_NUM_PORTS; port++) {
  724. ar8xxx_reg_clear(priv, AR8327_REG_PORT_LOOKUP(port),
  725. AR8327_PORT_LOOKUP_ING_MIRROR_EN);
  726. ar8xxx_reg_clear(priv, AR8327_REG_PORT_HOL_CTRL1(port),
  727. AR8327_PORT_HOL_CTRL1_EG_MIRROR_EN);
  728. }
  729. /* now enable mirroring if necessary */
  730. if (priv->source_port >= AR8327_NUM_PORTS ||
  731. priv->monitor_port >= AR8327_NUM_PORTS ||
  732. priv->source_port == priv->monitor_port) {
  733. return;
  734. }
  735. ar8xxx_rmw(priv, AR8327_REG_FWD_CTRL0,
  736. AR8327_FWD_CTRL0_MIRROR_PORT,
  737. (priv->monitor_port << AR8327_FWD_CTRL0_MIRROR_PORT_S));
  738. if (priv->mirror_rx)
  739. ar8xxx_reg_set(priv, AR8327_REG_PORT_LOOKUP(priv->source_port),
  740. AR8327_PORT_LOOKUP_ING_MIRROR_EN);
  741. if (priv->mirror_tx)
  742. ar8xxx_reg_set(priv, AR8327_REG_PORT_HOL_CTRL1(priv->source_port),
  743. AR8327_PORT_HOL_CTRL1_EG_MIRROR_EN);
  744. }
  745. static int
  746. ar8327_sw_set_eee(struct switch_dev *dev,
  747. const struct switch_attr *attr,
  748. struct switch_val *val)
  749. {
  750. struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
  751. struct ar8327_data *data = priv->chip_data;
  752. int port = val->port_vlan;
  753. int phy;
  754. if (port >= dev->ports)
  755. return -EINVAL;
  756. if (port == 0 || port == 6)
  757. return -EOPNOTSUPP;
  758. phy = port - 1;
  759. data->eee[phy] = !!(val->value.i);
  760. return 0;
  761. }
  762. static int
  763. ar8327_sw_get_eee(struct switch_dev *dev,
  764. const struct switch_attr *attr,
  765. struct switch_val *val)
  766. {
  767. struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
  768. const struct ar8327_data *data = priv->chip_data;
  769. int port = val->port_vlan;
  770. int phy;
  771. if (port >= dev->ports)
  772. return -EINVAL;
  773. if (port == 0 || port == 6)
  774. return -EOPNOTSUPP;
  775. phy = port - 1;
  776. val->value.i = data->eee[phy];
  777. return 0;
  778. }
  779. static void
  780. ar8327_wait_atu_ready(struct ar8xxx_priv *priv, u16 r2, u16 r1)
  781. {
  782. int timeout = 20;
  783. while (ar8xxx_mii_read32(priv, r2, r1) & AR8327_ATU_FUNC_BUSY && --timeout)
  784. udelay(10);
  785. if (!timeout)
  786. pr_err("ar8327: timeout waiting for atu to become ready\n");
  787. }
  788. static void ar8327_get_arl_entry(struct ar8xxx_priv *priv,
  789. struct arl_entry *a, u32 *status, enum arl_op op)
  790. {
  791. struct mii_bus *bus = priv->mii_bus;
  792. u16 r2, page;
  793. u16 r1_data0, r1_data1, r1_data2, r1_func;
  794. u32 t, val0, val1, val2;
  795. int i;
  796. split_addr(AR8327_REG_ATU_DATA0, &r1_data0, &r2, &page);
  797. r2 |= 0x10;
  798. r1_data1 = (AR8327_REG_ATU_DATA1 >> 1) & 0x1e;
  799. r1_data2 = (AR8327_REG_ATU_DATA2 >> 1) & 0x1e;
  800. r1_func = (AR8327_REG_ATU_FUNC >> 1) & 0x1e;
  801. switch (op) {
  802. case AR8XXX_ARL_INITIALIZE:
  803. /* all ATU registers are on the same page
  804. * therefore set page only once
  805. */
  806. bus->write(bus, 0x18, 0, page);
  807. wait_for_page_switch();
  808. ar8327_wait_atu_ready(priv, r2, r1_func);
  809. ar8xxx_mii_write32(priv, r2, r1_data0, 0);
  810. ar8xxx_mii_write32(priv, r2, r1_data1, 0);
  811. ar8xxx_mii_write32(priv, r2, r1_data2, 0);
  812. break;
  813. case AR8XXX_ARL_GET_NEXT:
  814. ar8xxx_mii_write32(priv, r2, r1_func,
  815. AR8327_ATU_FUNC_OP_GET_NEXT |
  816. AR8327_ATU_FUNC_BUSY);
  817. ar8327_wait_atu_ready(priv, r2, r1_func);
  818. val0 = ar8xxx_mii_read32(priv, r2, r1_data0);
  819. val1 = ar8xxx_mii_read32(priv, r2, r1_data1);
  820. val2 = ar8xxx_mii_read32(priv, r2, r1_data2);
  821. *status = val2 & AR8327_ATU_STATUS;
  822. if (!*status)
  823. break;
  824. i = 0;
  825. t = AR8327_ATU_PORT0;
  826. while (!(val1 & t) && ++i < AR8327_NUM_PORTS)
  827. t <<= 1;
  828. a->port = i;
  829. a->mac[0] = (val0 & AR8327_ATU_ADDR0) >> AR8327_ATU_ADDR0_S;
  830. a->mac[1] = (val0 & AR8327_ATU_ADDR1) >> AR8327_ATU_ADDR1_S;
  831. a->mac[2] = (val0 & AR8327_ATU_ADDR2) >> AR8327_ATU_ADDR2_S;
  832. a->mac[3] = (val0 & AR8327_ATU_ADDR3) >> AR8327_ATU_ADDR3_S;
  833. a->mac[4] = (val1 & AR8327_ATU_ADDR4) >> AR8327_ATU_ADDR4_S;
  834. a->mac[5] = (val1 & AR8327_ATU_ADDR5) >> AR8327_ATU_ADDR5_S;
  835. break;
  836. }
  837. }
  838. static int
  839. ar8327_sw_hw_apply(struct switch_dev *dev)
  840. {
  841. struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
  842. const struct ar8327_data *data = priv->chip_data;
  843. int ret, i;
  844. ret = ar8xxx_sw_hw_apply(dev);
  845. if (ret)
  846. return ret;
  847. for (i=0; i < AR8XXX_NUM_PHYS; i++) {
  848. if (data->eee[i])
  849. ar8xxx_reg_clear(priv, AR8327_REG_EEE_CTRL,
  850. AR8327_EEE_CTRL_DISABLE_PHY(i));
  851. else
  852. ar8xxx_reg_set(priv, AR8327_REG_EEE_CTRL,
  853. AR8327_EEE_CTRL_DISABLE_PHY(i));
  854. }
  855. return 0;
  856. }
  857. static const struct switch_attr ar8327_sw_attr_globals[] = {
  858. {
  859. .type = SWITCH_TYPE_INT,
  860. .name = "enable_vlan",
  861. .description = "Enable VLAN mode",
  862. .set = ar8xxx_sw_set_vlan,
  863. .get = ar8xxx_sw_get_vlan,
  864. .max = 1
  865. },
  866. {
  867. .type = SWITCH_TYPE_NOVAL,
  868. .name = "reset_mibs",
  869. .description = "Reset all MIB counters",
  870. .set = ar8xxx_sw_set_reset_mibs,
  871. },
  872. {
  873. .type = SWITCH_TYPE_INT,
  874. .name = "enable_mirror_rx",
  875. .description = "Enable mirroring of RX packets",
  876. .set = ar8xxx_sw_set_mirror_rx_enable,
  877. .get = ar8xxx_sw_get_mirror_rx_enable,
  878. .max = 1
  879. },
  880. {
  881. .type = SWITCH_TYPE_INT,
  882. .name = "enable_mirror_tx",
  883. .description = "Enable mirroring of TX packets",
  884. .set = ar8xxx_sw_set_mirror_tx_enable,
  885. .get = ar8xxx_sw_get_mirror_tx_enable,
  886. .max = 1
  887. },
  888. {
  889. .type = SWITCH_TYPE_INT,
  890. .name = "mirror_monitor_port",
  891. .description = "Mirror monitor port",
  892. .set = ar8xxx_sw_set_mirror_monitor_port,
  893. .get = ar8xxx_sw_get_mirror_monitor_port,
  894. .max = AR8327_NUM_PORTS - 1
  895. },
  896. {
  897. .type = SWITCH_TYPE_INT,
  898. .name = "mirror_source_port",
  899. .description = "Mirror source port",
  900. .set = ar8xxx_sw_set_mirror_source_port,
  901. .get = ar8xxx_sw_get_mirror_source_port,
  902. .max = AR8327_NUM_PORTS - 1
  903. },
  904. {
  905. .type = SWITCH_TYPE_STRING,
  906. .name = "arl_table",
  907. .description = "Get ARL table",
  908. .set = NULL,
  909. .get = ar8xxx_sw_get_arl_table,
  910. },
  911. };
  912. static const struct switch_attr ar8327_sw_attr_port[] = {
  913. {
  914. .type = SWITCH_TYPE_NOVAL,
  915. .name = "reset_mib",
  916. .description = "Reset single port MIB counters",
  917. .set = ar8xxx_sw_set_port_reset_mib,
  918. },
  919. {
  920. .type = SWITCH_TYPE_STRING,
  921. .name = "mib",
  922. .description = "Get port's MIB counters",
  923. .set = NULL,
  924. .get = ar8xxx_sw_get_port_mib,
  925. },
  926. {
  927. .type = SWITCH_TYPE_INT,
  928. .name = "enable_eee",
  929. .description = "Enable EEE PHY sleep mode",
  930. .set = ar8327_sw_set_eee,
  931. .get = ar8327_sw_get_eee,
  932. .max = 1,
  933. },
  934. };
  935. static const struct switch_dev_ops ar8327_sw_ops = {
  936. .attr_global = {
  937. .attr = ar8327_sw_attr_globals,
  938. .n_attr = ARRAY_SIZE(ar8327_sw_attr_globals),
  939. },
  940. .attr_port = {
  941. .attr = ar8327_sw_attr_port,
  942. .n_attr = ARRAY_SIZE(ar8327_sw_attr_port),
  943. },
  944. .attr_vlan = {
  945. .attr = ar8xxx_sw_attr_vlan,
  946. .n_attr = ARRAY_SIZE(ar8xxx_sw_attr_vlan),
  947. },
  948. .get_port_pvid = ar8xxx_sw_get_pvid,
  949. .set_port_pvid = ar8xxx_sw_set_pvid,
  950. .get_vlan_ports = ar8327_sw_get_ports,
  951. .set_vlan_ports = ar8327_sw_set_ports,
  952. .apply_config = ar8327_sw_hw_apply,
  953. .reset_switch = ar8xxx_sw_reset_switch,
  954. .get_port_link = ar8xxx_sw_get_port_link,
  955. };
  956. const struct ar8xxx_chip ar8327_chip = {
  957. .caps = AR8XXX_CAP_GIGE | AR8XXX_CAP_MIB_COUNTERS,
  958. .config_at_probe = true,
  959. .mii_lo_first = true,
  960. .name = "Atheros AR8327",
  961. .ports = AR8327_NUM_PORTS,
  962. .vlans = AR8X16_MAX_VLANS,
  963. .swops = &ar8327_sw_ops,
  964. .reg_port_stats_start = 0x1000,
  965. .reg_port_stats_length = 0x100,
  966. .hw_init = ar8327_hw_init,
  967. .cleanup = ar8327_cleanup,
  968. .init_globals = ar8327_init_globals,
  969. .init_port = ar8327_init_port,
  970. .setup_port = ar8327_setup_port,
  971. .read_port_status = ar8327_read_port_status,
  972. .read_port_eee_status = ar8327_read_port_eee_status,
  973. .atu_flush = ar8327_atu_flush,
  974. .vtu_flush = ar8327_vtu_flush,
  975. .vtu_load_vlan = ar8327_vtu_load_vlan,
  976. .phy_fixup = ar8327_phy_fixup,
  977. .set_mirror_regs = ar8327_set_mirror_regs,
  978. .get_arl_entry = ar8327_get_arl_entry,
  979. .sw_hw_apply = ar8327_sw_hw_apply,
  980. .num_mibs = ARRAY_SIZE(ar8236_mibs),
  981. .mib_decs = ar8236_mibs,
  982. .mib_func = AR8327_REG_MIB_FUNC
  983. };
  984. const struct ar8xxx_chip ar8337_chip = {
  985. .caps = AR8XXX_CAP_GIGE | AR8XXX_CAP_MIB_COUNTERS,
  986. .config_at_probe = true,
  987. .mii_lo_first = true,
  988. .name = "Atheros AR8337",
  989. .ports = AR8327_NUM_PORTS,
  990. .vlans = AR8X16_MAX_VLANS,
  991. .swops = &ar8327_sw_ops,
  992. .reg_port_stats_start = 0x1000,
  993. .reg_port_stats_length = 0x100,
  994. .hw_init = ar8327_hw_init,
  995. .cleanup = ar8327_cleanup,
  996. .init_globals = ar8327_init_globals,
  997. .init_port = ar8327_init_port,
  998. .setup_port = ar8327_setup_port,
  999. .read_port_status = ar8327_read_port_status,
  1000. .read_port_eee_status = ar8327_read_port_eee_status,
  1001. .atu_flush = ar8327_atu_flush,
  1002. .vtu_flush = ar8327_vtu_flush,
  1003. .vtu_load_vlan = ar8327_vtu_load_vlan,
  1004. .phy_fixup = ar8327_phy_fixup,
  1005. .set_mirror_regs = ar8327_set_mirror_regs,
  1006. .get_arl_entry = ar8327_get_arl_entry,
  1007. .sw_hw_apply = ar8327_sw_hw_apply,
  1008. .num_mibs = ARRAY_SIZE(ar8236_mibs),
  1009. .mib_decs = ar8236_mibs,
  1010. .mib_func = AR8327_REG_MIB_FUNC
  1011. };