dwc-xlgmac-common.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* Synopsys DesignWare Core Enterprise Ethernet (XLGMAC) Driver
  2. *
  3. * Copyright (c) 2017 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * This program is dual-licensed; you may select either version 2 of
  6. * the GNU General Public License ("GPL") or BSD license ("BSD").
  7. *
  8. * This Synopsys DWC XLGMAC software driver and associated documentation
  9. * (hereinafter the "Software") is an unsupported proprietary work of
  10. * Synopsys, Inc. unless otherwise expressly agreed to in writing between
  11. * Synopsys and you. The Software IS NOT an item of Licensed Software or a
  12. * Licensed Product under any End User Software License Agreement or
  13. * Agreement for Licensed Products with Synopsys or any supplement thereto.
  14. * Synopsys is a registered trademark of Synopsys, Inc. Other names included
  15. * in the SOFTWARE may be the trademarks of their respective owners.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include "dwc-xlgmac.h"
  20. #include "dwc-xlgmac-reg.h"
  21. MODULE_LICENSE("Dual BSD/GPL");
  22. static int debug = -1;
  23. module_param(debug, int, 0644);
  24. MODULE_PARM_DESC(debug, "DWC ethernet debug level (0=none,...,16=all)");
  25. static const u32 default_msg_level = (NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  26. NETIF_MSG_IFUP);
  27. static unsigned char dev_addr[6] = {0, 0x55, 0x7b, 0xb5, 0x7d, 0xf7};
  28. static void xlgmac_read_mac_addr(struct xlgmac_pdata *pdata)
  29. {
  30. struct net_device *netdev = pdata->netdev;
  31. /* Currently it uses a static mac address for test */
  32. memcpy(pdata->mac_addr, dev_addr, netdev->addr_len);
  33. }
  34. static void xlgmac_default_config(struct xlgmac_pdata *pdata)
  35. {
  36. pdata->tx_osp_mode = DMA_OSP_ENABLE;
  37. pdata->tx_sf_mode = MTL_TSF_ENABLE;
  38. pdata->rx_sf_mode = MTL_RSF_DISABLE;
  39. pdata->pblx8 = DMA_PBL_X8_ENABLE;
  40. pdata->tx_pbl = DMA_PBL_32;
  41. pdata->rx_pbl = DMA_PBL_32;
  42. pdata->tx_threshold = MTL_TX_THRESHOLD_128;
  43. pdata->rx_threshold = MTL_RX_THRESHOLD_128;
  44. pdata->tx_pause = 1;
  45. pdata->rx_pause = 1;
  46. pdata->phy_speed = SPEED_25000;
  47. pdata->sysclk_rate = XLGMAC_SYSCLOCK;
  48. strscpy(pdata->drv_name, XLGMAC_DRV_NAME, sizeof(pdata->drv_name));
  49. strscpy(pdata->drv_ver, XLGMAC_DRV_VERSION, sizeof(pdata->drv_ver));
  50. }
  51. static void xlgmac_init_all_ops(struct xlgmac_pdata *pdata)
  52. {
  53. xlgmac_init_desc_ops(&pdata->desc_ops);
  54. xlgmac_init_hw_ops(&pdata->hw_ops);
  55. }
  56. static int xlgmac_init(struct xlgmac_pdata *pdata)
  57. {
  58. struct xlgmac_hw_ops *hw_ops = &pdata->hw_ops;
  59. struct net_device *netdev = pdata->netdev;
  60. unsigned int i;
  61. int ret;
  62. /* Set default configuration data */
  63. xlgmac_default_config(pdata);
  64. /* Set irq, base_addr, MAC address, */
  65. netdev->irq = pdata->dev_irq;
  66. netdev->base_addr = (unsigned long)pdata->mac_regs;
  67. xlgmac_read_mac_addr(pdata);
  68. eth_hw_addr_set(netdev, pdata->mac_addr);
  69. /* Set all the function pointers */
  70. xlgmac_init_all_ops(pdata);
  71. /* Issue software reset to device */
  72. hw_ops->exit(pdata);
  73. /* Populate the hardware features */
  74. xlgmac_get_all_hw_features(pdata);
  75. xlgmac_print_all_hw_features(pdata);
  76. /* TODO: Set the PHY mode to XLGMII */
  77. /* Set the DMA mask */
  78. ret = dma_set_mask_and_coherent(pdata->dev,
  79. DMA_BIT_MASK(pdata->hw_feat.dma_width));
  80. if (ret) {
  81. dev_err(pdata->dev, "dma_set_mask_and_coherent failed\n");
  82. return ret;
  83. }
  84. /* Channel and ring params initializtion
  85. * pdata->channel_count;
  86. * pdata->tx_ring_count;
  87. * pdata->rx_ring_count;
  88. * pdata->tx_desc_count;
  89. * pdata->rx_desc_count;
  90. */
  91. BUILD_BUG_ON_NOT_POWER_OF_2(XLGMAC_TX_DESC_CNT);
  92. pdata->tx_desc_count = XLGMAC_TX_DESC_CNT;
  93. if (pdata->tx_desc_count & (pdata->tx_desc_count - 1)) {
  94. dev_err(pdata->dev, "tx descriptor count (%d) is not valid\n",
  95. pdata->tx_desc_count);
  96. ret = -EINVAL;
  97. return ret;
  98. }
  99. BUILD_BUG_ON_NOT_POWER_OF_2(XLGMAC_RX_DESC_CNT);
  100. pdata->rx_desc_count = XLGMAC_RX_DESC_CNT;
  101. if (pdata->rx_desc_count & (pdata->rx_desc_count - 1)) {
  102. dev_err(pdata->dev, "rx descriptor count (%d) is not valid\n",
  103. pdata->rx_desc_count);
  104. ret = -EINVAL;
  105. return ret;
  106. }
  107. pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(),
  108. pdata->hw_feat.tx_ch_cnt);
  109. pdata->tx_ring_count = min_t(unsigned int, pdata->tx_ring_count,
  110. pdata->hw_feat.tx_q_cnt);
  111. pdata->tx_q_count = pdata->tx_ring_count;
  112. ret = netif_set_real_num_tx_queues(netdev, pdata->tx_q_count);
  113. if (ret) {
  114. dev_err(pdata->dev, "error setting real tx queue count\n");
  115. return ret;
  116. }
  117. pdata->rx_ring_count = min_t(unsigned int,
  118. netif_get_num_default_rss_queues(),
  119. pdata->hw_feat.rx_ch_cnt);
  120. pdata->rx_ring_count = min_t(unsigned int, pdata->rx_ring_count,
  121. pdata->hw_feat.rx_q_cnt);
  122. pdata->rx_q_count = pdata->rx_ring_count;
  123. ret = netif_set_real_num_rx_queues(netdev, pdata->rx_q_count);
  124. if (ret) {
  125. dev_err(pdata->dev, "error setting real rx queue count\n");
  126. return ret;
  127. }
  128. pdata->channel_count =
  129. max_t(unsigned int, pdata->tx_ring_count, pdata->rx_ring_count);
  130. /* Initialize RSS hash key and lookup table */
  131. netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key));
  132. for (i = 0; i < XLGMAC_RSS_MAX_TABLE_SIZE; i++)
  133. pdata->rss_table[i] = XLGMAC_SET_REG_BITS(
  134. pdata->rss_table[i],
  135. MAC_RSSDR_DMCH_POS,
  136. MAC_RSSDR_DMCH_LEN,
  137. i % pdata->rx_ring_count);
  138. pdata->rss_options = XLGMAC_SET_REG_BITS(
  139. pdata->rss_options,
  140. MAC_RSSCR_IP2TE_POS,
  141. MAC_RSSCR_IP2TE_LEN, 1);
  142. pdata->rss_options = XLGMAC_SET_REG_BITS(
  143. pdata->rss_options,
  144. MAC_RSSCR_TCP4TE_POS,
  145. MAC_RSSCR_TCP4TE_LEN, 1);
  146. pdata->rss_options = XLGMAC_SET_REG_BITS(
  147. pdata->rss_options,
  148. MAC_RSSCR_UDP4TE_POS,
  149. MAC_RSSCR_UDP4TE_LEN, 1);
  150. /* Set device operations */
  151. netdev->netdev_ops = xlgmac_get_netdev_ops();
  152. netdev->ethtool_ops = xlgmac_get_ethtool_ops();
  153. /* Set device features */
  154. if (pdata->hw_feat.tso) {
  155. netdev->hw_features = NETIF_F_TSO;
  156. netdev->hw_features |= NETIF_F_TSO6;
  157. netdev->hw_features |= NETIF_F_SG;
  158. netdev->hw_features |= NETIF_F_IP_CSUM;
  159. netdev->hw_features |= NETIF_F_IPV6_CSUM;
  160. } else if (pdata->hw_feat.tx_coe) {
  161. netdev->hw_features = NETIF_F_IP_CSUM;
  162. netdev->hw_features |= NETIF_F_IPV6_CSUM;
  163. }
  164. if (pdata->hw_feat.rx_coe) {
  165. netdev->hw_features |= NETIF_F_RXCSUM;
  166. netdev->hw_features |= NETIF_F_GRO;
  167. }
  168. if (pdata->hw_feat.rss)
  169. netdev->hw_features |= NETIF_F_RXHASH;
  170. netdev->vlan_features |= netdev->hw_features;
  171. netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
  172. if (pdata->hw_feat.sa_vlan_ins)
  173. netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
  174. if (pdata->hw_feat.vlhash)
  175. netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  176. netdev->features |= netdev->hw_features;
  177. pdata->netdev_features = netdev->features;
  178. netdev->priv_flags |= IFF_UNICAST_FLT;
  179. /* Use default watchdog timeout */
  180. netdev->watchdog_timeo = 0;
  181. /* Tx coalesce parameters initialization */
  182. pdata->tx_usecs = XLGMAC_INIT_DMA_TX_USECS;
  183. pdata->tx_frames = XLGMAC_INIT_DMA_TX_FRAMES;
  184. /* Rx coalesce parameters initialization */
  185. pdata->rx_riwt = hw_ops->usec_to_riwt(pdata, XLGMAC_INIT_DMA_RX_USECS);
  186. pdata->rx_usecs = XLGMAC_INIT_DMA_RX_USECS;
  187. pdata->rx_frames = XLGMAC_INIT_DMA_RX_FRAMES;
  188. return 0;
  189. }
  190. int xlgmac_drv_probe(struct device *dev, struct xlgmac_resources *res)
  191. {
  192. struct xlgmac_pdata *pdata;
  193. struct net_device *netdev;
  194. int ret;
  195. netdev = alloc_etherdev_mq(sizeof(struct xlgmac_pdata),
  196. XLGMAC_MAX_DMA_CHANNELS);
  197. if (!netdev) {
  198. dev_err(dev, "alloc_etherdev failed\n");
  199. return -ENOMEM;
  200. }
  201. SET_NETDEV_DEV(netdev, dev);
  202. dev_set_drvdata(dev, netdev);
  203. pdata = netdev_priv(netdev);
  204. pdata->dev = dev;
  205. pdata->netdev = netdev;
  206. pdata->dev_irq = res->irq;
  207. pdata->mac_regs = res->addr;
  208. mutex_init(&pdata->rss_mutex);
  209. pdata->msg_enable = netif_msg_init(debug, default_msg_level);
  210. ret = xlgmac_init(pdata);
  211. if (ret) {
  212. dev_err(dev, "xlgmac init failed\n");
  213. goto err_free_netdev;
  214. }
  215. ret = register_netdev(netdev);
  216. if (ret) {
  217. dev_err(dev, "net device registration failed\n");
  218. goto err_free_netdev;
  219. }
  220. return 0;
  221. err_free_netdev:
  222. free_netdev(netdev);
  223. return ret;
  224. }
  225. int xlgmac_drv_remove(struct device *dev)
  226. {
  227. struct net_device *netdev = dev_get_drvdata(dev);
  228. unregister_netdev(netdev);
  229. free_netdev(netdev);
  230. return 0;
  231. }
  232. void xlgmac_dump_tx_desc(struct xlgmac_pdata *pdata,
  233. struct xlgmac_ring *ring,
  234. unsigned int idx,
  235. unsigned int count,
  236. unsigned int flag)
  237. {
  238. struct xlgmac_desc_data *desc_data;
  239. struct xlgmac_dma_desc *dma_desc;
  240. while (count--) {
  241. desc_data = XLGMAC_GET_DESC_DATA(ring, idx);
  242. dma_desc = desc_data->dma_desc;
  243. netdev_dbg(pdata->netdev, "TX: dma_desc=%p, dma_desc_addr=%pad\n",
  244. desc_data->dma_desc, &desc_data->dma_desc_addr);
  245. netdev_dbg(pdata->netdev,
  246. "TX_NORMAL_DESC[%d %s] = %08x:%08x:%08x:%08x\n", idx,
  247. (flag == 1) ? "QUEUED FOR TX" : "TX BY DEVICE",
  248. le32_to_cpu(dma_desc->desc0),
  249. le32_to_cpu(dma_desc->desc1),
  250. le32_to_cpu(dma_desc->desc2),
  251. le32_to_cpu(dma_desc->desc3));
  252. idx++;
  253. }
  254. }
  255. void xlgmac_dump_rx_desc(struct xlgmac_pdata *pdata,
  256. struct xlgmac_ring *ring,
  257. unsigned int idx)
  258. {
  259. struct xlgmac_desc_data *desc_data;
  260. struct xlgmac_dma_desc *dma_desc;
  261. desc_data = XLGMAC_GET_DESC_DATA(ring, idx);
  262. dma_desc = desc_data->dma_desc;
  263. netdev_dbg(pdata->netdev, "RX: dma_desc=%p, dma_desc_addr=%pad\n",
  264. desc_data->dma_desc, &desc_data->dma_desc_addr);
  265. netdev_dbg(pdata->netdev,
  266. "RX_NORMAL_DESC[%d RX BY DEVICE] = %08x:%08x:%08x:%08x\n",
  267. idx,
  268. le32_to_cpu(dma_desc->desc0),
  269. le32_to_cpu(dma_desc->desc1),
  270. le32_to_cpu(dma_desc->desc2),
  271. le32_to_cpu(dma_desc->desc3));
  272. }
  273. void xlgmac_print_pkt(struct net_device *netdev,
  274. struct sk_buff *skb, bool tx_rx)
  275. {
  276. struct ethhdr *eth = (struct ethhdr *)skb->data;
  277. unsigned char buffer[128];
  278. unsigned int i;
  279. netdev_dbg(netdev, "\n************** SKB dump ****************\n");
  280. netdev_dbg(netdev, "%s packet of %d bytes\n",
  281. (tx_rx ? "TX" : "RX"), skb->len);
  282. netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest);
  283. netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source);
  284. netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
  285. for (i = 0; i < skb->len; i += 32) {
  286. unsigned int len = min(skb->len - i, 32U);
  287. hex_dump_to_buffer(&skb->data[i], len, 32, 1,
  288. buffer, sizeof(buffer), false);
  289. netdev_dbg(netdev, " %#06x: %s\n", i, buffer);
  290. }
  291. netdev_dbg(netdev, "\n************** SKB dump ****************\n");
  292. }
  293. void xlgmac_get_all_hw_features(struct xlgmac_pdata *pdata)
  294. {
  295. struct xlgmac_hw_features *hw_feat = &pdata->hw_feat;
  296. unsigned int mac_hfr0, mac_hfr1, mac_hfr2;
  297. mac_hfr0 = readl(pdata->mac_regs + MAC_HWF0R);
  298. mac_hfr1 = readl(pdata->mac_regs + MAC_HWF1R);
  299. mac_hfr2 = readl(pdata->mac_regs + MAC_HWF2R);
  300. memset(hw_feat, 0, sizeof(*hw_feat));
  301. hw_feat->version = readl(pdata->mac_regs + MAC_VR);
  302. /* Hardware feature register 0 */
  303. hw_feat->phyifsel = XLGMAC_GET_REG_BITS(mac_hfr0,
  304. MAC_HWF0R_PHYIFSEL_POS,
  305. MAC_HWF0R_PHYIFSEL_LEN);
  306. hw_feat->vlhash = XLGMAC_GET_REG_BITS(mac_hfr0,
  307. MAC_HWF0R_VLHASH_POS,
  308. MAC_HWF0R_VLHASH_LEN);
  309. hw_feat->sma = XLGMAC_GET_REG_BITS(mac_hfr0,
  310. MAC_HWF0R_SMASEL_POS,
  311. MAC_HWF0R_SMASEL_LEN);
  312. hw_feat->rwk = XLGMAC_GET_REG_BITS(mac_hfr0,
  313. MAC_HWF0R_RWKSEL_POS,
  314. MAC_HWF0R_RWKSEL_LEN);
  315. hw_feat->mgk = XLGMAC_GET_REG_BITS(mac_hfr0,
  316. MAC_HWF0R_MGKSEL_POS,
  317. MAC_HWF0R_MGKSEL_LEN);
  318. hw_feat->mmc = XLGMAC_GET_REG_BITS(mac_hfr0,
  319. MAC_HWF0R_MMCSEL_POS,
  320. MAC_HWF0R_MMCSEL_LEN);
  321. hw_feat->aoe = XLGMAC_GET_REG_BITS(mac_hfr0,
  322. MAC_HWF0R_ARPOFFSEL_POS,
  323. MAC_HWF0R_ARPOFFSEL_LEN);
  324. hw_feat->ts = XLGMAC_GET_REG_BITS(mac_hfr0,
  325. MAC_HWF0R_TSSEL_POS,
  326. MAC_HWF0R_TSSEL_LEN);
  327. hw_feat->eee = XLGMAC_GET_REG_BITS(mac_hfr0,
  328. MAC_HWF0R_EEESEL_POS,
  329. MAC_HWF0R_EEESEL_LEN);
  330. hw_feat->tx_coe = XLGMAC_GET_REG_BITS(mac_hfr0,
  331. MAC_HWF0R_TXCOESEL_POS,
  332. MAC_HWF0R_TXCOESEL_LEN);
  333. hw_feat->rx_coe = XLGMAC_GET_REG_BITS(mac_hfr0,
  334. MAC_HWF0R_RXCOESEL_POS,
  335. MAC_HWF0R_RXCOESEL_LEN);
  336. hw_feat->addn_mac = XLGMAC_GET_REG_BITS(mac_hfr0,
  337. MAC_HWF0R_ADDMACADRSEL_POS,
  338. MAC_HWF0R_ADDMACADRSEL_LEN);
  339. hw_feat->ts_src = XLGMAC_GET_REG_BITS(mac_hfr0,
  340. MAC_HWF0R_TSSTSSEL_POS,
  341. MAC_HWF0R_TSSTSSEL_LEN);
  342. hw_feat->sa_vlan_ins = XLGMAC_GET_REG_BITS(mac_hfr0,
  343. MAC_HWF0R_SAVLANINS_POS,
  344. MAC_HWF0R_SAVLANINS_LEN);
  345. /* Hardware feature register 1 */
  346. hw_feat->rx_fifo_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  347. MAC_HWF1R_RXFIFOSIZE_POS,
  348. MAC_HWF1R_RXFIFOSIZE_LEN);
  349. hw_feat->tx_fifo_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  350. MAC_HWF1R_TXFIFOSIZE_POS,
  351. MAC_HWF1R_TXFIFOSIZE_LEN);
  352. hw_feat->adv_ts_hi = XLGMAC_GET_REG_BITS(mac_hfr1,
  353. MAC_HWF1R_ADVTHWORD_POS,
  354. MAC_HWF1R_ADVTHWORD_LEN);
  355. hw_feat->dma_width = XLGMAC_GET_REG_BITS(mac_hfr1,
  356. MAC_HWF1R_ADDR64_POS,
  357. MAC_HWF1R_ADDR64_LEN);
  358. hw_feat->dcb = XLGMAC_GET_REG_BITS(mac_hfr1,
  359. MAC_HWF1R_DCBEN_POS,
  360. MAC_HWF1R_DCBEN_LEN);
  361. hw_feat->sph = XLGMAC_GET_REG_BITS(mac_hfr1,
  362. MAC_HWF1R_SPHEN_POS,
  363. MAC_HWF1R_SPHEN_LEN);
  364. hw_feat->tso = XLGMAC_GET_REG_BITS(mac_hfr1,
  365. MAC_HWF1R_TSOEN_POS,
  366. MAC_HWF1R_TSOEN_LEN);
  367. hw_feat->dma_debug = XLGMAC_GET_REG_BITS(mac_hfr1,
  368. MAC_HWF1R_DBGMEMA_POS,
  369. MAC_HWF1R_DBGMEMA_LEN);
  370. hw_feat->rss = XLGMAC_GET_REG_BITS(mac_hfr1,
  371. MAC_HWF1R_RSSEN_POS,
  372. MAC_HWF1R_RSSEN_LEN);
  373. hw_feat->tc_cnt = XLGMAC_GET_REG_BITS(mac_hfr1,
  374. MAC_HWF1R_NUMTC_POS,
  375. MAC_HWF1R_NUMTC_LEN);
  376. hw_feat->hash_table_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  377. MAC_HWF1R_HASHTBLSZ_POS,
  378. MAC_HWF1R_HASHTBLSZ_LEN);
  379. hw_feat->l3l4_filter_num = XLGMAC_GET_REG_BITS(mac_hfr1,
  380. MAC_HWF1R_L3L4FNUM_POS,
  381. MAC_HWF1R_L3L4FNUM_LEN);
  382. /* Hardware feature register 2 */
  383. hw_feat->rx_q_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  384. MAC_HWF2R_RXQCNT_POS,
  385. MAC_HWF2R_RXQCNT_LEN);
  386. hw_feat->tx_q_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  387. MAC_HWF2R_TXQCNT_POS,
  388. MAC_HWF2R_TXQCNT_LEN);
  389. hw_feat->rx_ch_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  390. MAC_HWF2R_RXCHCNT_POS,
  391. MAC_HWF2R_RXCHCNT_LEN);
  392. hw_feat->tx_ch_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  393. MAC_HWF2R_TXCHCNT_POS,
  394. MAC_HWF2R_TXCHCNT_LEN);
  395. hw_feat->pps_out_num = XLGMAC_GET_REG_BITS(mac_hfr2,
  396. MAC_HWF2R_PPSOUTNUM_POS,
  397. MAC_HWF2R_PPSOUTNUM_LEN);
  398. hw_feat->aux_snap_num = XLGMAC_GET_REG_BITS(mac_hfr2,
  399. MAC_HWF2R_AUXSNAPNUM_POS,
  400. MAC_HWF2R_AUXSNAPNUM_LEN);
  401. /* Translate the Hash Table size into actual number */
  402. switch (hw_feat->hash_table_size) {
  403. case 0:
  404. break;
  405. case 1:
  406. hw_feat->hash_table_size = 64;
  407. break;
  408. case 2:
  409. hw_feat->hash_table_size = 128;
  410. break;
  411. case 3:
  412. hw_feat->hash_table_size = 256;
  413. break;
  414. }
  415. /* Translate the address width setting into actual number */
  416. switch (hw_feat->dma_width) {
  417. case 0:
  418. hw_feat->dma_width = 32;
  419. break;
  420. case 1:
  421. hw_feat->dma_width = 40;
  422. break;
  423. case 2:
  424. hw_feat->dma_width = 48;
  425. break;
  426. default:
  427. hw_feat->dma_width = 32;
  428. }
  429. /* The Queue, Channel and TC counts are zero based so increment them
  430. * to get the actual number
  431. */
  432. hw_feat->rx_q_cnt++;
  433. hw_feat->tx_q_cnt++;
  434. hw_feat->rx_ch_cnt++;
  435. hw_feat->tx_ch_cnt++;
  436. hw_feat->tc_cnt++;
  437. }
  438. void xlgmac_print_all_hw_features(struct xlgmac_pdata *pdata)
  439. {
  440. char __maybe_unused *str = NULL;
  441. XLGMAC_PR("\n");
  442. XLGMAC_PR("=====================================================\n");
  443. XLGMAC_PR("\n");
  444. XLGMAC_PR("HW support following features\n");
  445. XLGMAC_PR("\n");
  446. /* HW Feature Register0 */
  447. XLGMAC_PR("VLAN Hash Filter Selected : %s\n",
  448. pdata->hw_feat.vlhash ? "YES" : "NO");
  449. XLGMAC_PR("SMA (MDIO) Interface : %s\n",
  450. pdata->hw_feat.sma ? "YES" : "NO");
  451. XLGMAC_PR("PMT Remote Wake-up Packet Enable : %s\n",
  452. pdata->hw_feat.rwk ? "YES" : "NO");
  453. XLGMAC_PR("PMT Magic Packet Enable : %s\n",
  454. pdata->hw_feat.mgk ? "YES" : "NO");
  455. XLGMAC_PR("RMON/MMC Module Enable : %s\n",
  456. pdata->hw_feat.mmc ? "YES" : "NO");
  457. XLGMAC_PR("ARP Offload Enabled : %s\n",
  458. pdata->hw_feat.aoe ? "YES" : "NO");
  459. XLGMAC_PR("IEEE 1588-2008 Timestamp Enabled : %s\n",
  460. pdata->hw_feat.ts ? "YES" : "NO");
  461. XLGMAC_PR("Energy Efficient Ethernet Enabled : %s\n",
  462. pdata->hw_feat.eee ? "YES" : "NO");
  463. XLGMAC_PR("Transmit Checksum Offload Enabled : %s\n",
  464. pdata->hw_feat.tx_coe ? "YES" : "NO");
  465. XLGMAC_PR("Receive Checksum Offload Enabled : %s\n",
  466. pdata->hw_feat.rx_coe ? "YES" : "NO");
  467. XLGMAC_PR("Additional MAC Addresses 1-31 Selected : %s\n",
  468. pdata->hw_feat.addn_mac ? "YES" : "NO");
  469. switch (pdata->hw_feat.ts_src) {
  470. case 0:
  471. str = "RESERVED";
  472. break;
  473. case 1:
  474. str = "INTERNAL";
  475. break;
  476. case 2:
  477. str = "EXTERNAL";
  478. break;
  479. case 3:
  480. str = "BOTH";
  481. break;
  482. }
  483. XLGMAC_PR("Timestamp System Time Source : %s\n", str);
  484. XLGMAC_PR("Source Address or VLAN Insertion Enable : %s\n",
  485. pdata->hw_feat.sa_vlan_ins ? "YES" : "NO");
  486. /* HW Feature Register1 */
  487. switch (pdata->hw_feat.rx_fifo_size) {
  488. case 0:
  489. str = "128 bytes";
  490. break;
  491. case 1:
  492. str = "256 bytes";
  493. break;
  494. case 2:
  495. str = "512 bytes";
  496. break;
  497. case 3:
  498. str = "1 KBytes";
  499. break;
  500. case 4:
  501. str = "2 KBytes";
  502. break;
  503. case 5:
  504. str = "4 KBytes";
  505. break;
  506. case 6:
  507. str = "8 KBytes";
  508. break;
  509. case 7:
  510. str = "16 KBytes";
  511. break;
  512. case 8:
  513. str = "32 kBytes";
  514. break;
  515. case 9:
  516. str = "64 KBytes";
  517. break;
  518. case 10:
  519. str = "128 KBytes";
  520. break;
  521. case 11:
  522. str = "256 KBytes";
  523. break;
  524. default:
  525. str = "RESERVED";
  526. }
  527. XLGMAC_PR("MTL Receive FIFO Size : %s\n", str);
  528. switch (pdata->hw_feat.tx_fifo_size) {
  529. case 0:
  530. str = "128 bytes";
  531. break;
  532. case 1:
  533. str = "256 bytes";
  534. break;
  535. case 2:
  536. str = "512 bytes";
  537. break;
  538. case 3:
  539. str = "1 KBytes";
  540. break;
  541. case 4:
  542. str = "2 KBytes";
  543. break;
  544. case 5:
  545. str = "4 KBytes";
  546. break;
  547. case 6:
  548. str = "8 KBytes";
  549. break;
  550. case 7:
  551. str = "16 KBytes";
  552. break;
  553. case 8:
  554. str = "32 kBytes";
  555. break;
  556. case 9:
  557. str = "64 KBytes";
  558. break;
  559. case 10:
  560. str = "128 KBytes";
  561. break;
  562. case 11:
  563. str = "256 KBytes";
  564. break;
  565. default:
  566. str = "RESERVED";
  567. }
  568. XLGMAC_PR("MTL Transmit FIFO Size : %s\n", str);
  569. XLGMAC_PR("IEEE 1588 High Word Register Enable : %s\n",
  570. pdata->hw_feat.adv_ts_hi ? "YES" : "NO");
  571. XLGMAC_PR("Address width : %u\n",
  572. pdata->hw_feat.dma_width);
  573. XLGMAC_PR("DCB Feature Enable : %s\n",
  574. pdata->hw_feat.dcb ? "YES" : "NO");
  575. XLGMAC_PR("Split Header Feature Enable : %s\n",
  576. pdata->hw_feat.sph ? "YES" : "NO");
  577. XLGMAC_PR("TCP Segmentation Offload Enable : %s\n",
  578. pdata->hw_feat.tso ? "YES" : "NO");
  579. XLGMAC_PR("DMA Debug Registers Enabled : %s\n",
  580. pdata->hw_feat.dma_debug ? "YES" : "NO");
  581. XLGMAC_PR("RSS Feature Enabled : %s\n",
  582. pdata->hw_feat.rss ? "YES" : "NO");
  583. XLGMAC_PR("Number of Traffic classes : %u\n",
  584. (pdata->hw_feat.tc_cnt));
  585. XLGMAC_PR("Hash Table Size : %u\n",
  586. pdata->hw_feat.hash_table_size);
  587. XLGMAC_PR("Total number of L3 or L4 Filters : %u\n",
  588. pdata->hw_feat.l3l4_filter_num);
  589. /* HW Feature Register2 */
  590. XLGMAC_PR("Number of MTL Receive Queues : %u\n",
  591. pdata->hw_feat.rx_q_cnt);
  592. XLGMAC_PR("Number of MTL Transmit Queues : %u\n",
  593. pdata->hw_feat.tx_q_cnt);
  594. XLGMAC_PR("Number of DMA Receive Channels : %u\n",
  595. pdata->hw_feat.rx_ch_cnt);
  596. XLGMAC_PR("Number of DMA Transmit Channels : %u\n",
  597. pdata->hw_feat.tx_ch_cnt);
  598. switch (pdata->hw_feat.pps_out_num) {
  599. case 0:
  600. str = "No PPS output";
  601. break;
  602. case 1:
  603. str = "1 PPS output";
  604. break;
  605. case 2:
  606. str = "2 PPS output";
  607. break;
  608. case 3:
  609. str = "3 PPS output";
  610. break;
  611. case 4:
  612. str = "4 PPS output";
  613. break;
  614. default:
  615. str = "RESERVED";
  616. }
  617. XLGMAC_PR("Number of PPS Outputs : %s\n", str);
  618. switch (pdata->hw_feat.aux_snap_num) {
  619. case 0:
  620. str = "No auxiliary input";
  621. break;
  622. case 1:
  623. str = "1 auxiliary input";
  624. break;
  625. case 2:
  626. str = "2 auxiliary input";
  627. break;
  628. case 3:
  629. str = "3 auxiliary input";
  630. break;
  631. case 4:
  632. str = "4 auxiliary input";
  633. break;
  634. default:
  635. str = "RESERVED";
  636. }
  637. XLGMAC_PR("Number of Auxiliary Snapshot Inputs : %s", str);
  638. XLGMAC_PR("\n");
  639. XLGMAC_PR("=====================================================\n");
  640. XLGMAC_PR("\n");
  641. }