dwc-xlgmac-common.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. strlcpy(pdata->drv_name, XLGMAC_DRV_NAME, sizeof(pdata->drv_name));
  49. strlcpy(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. memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len);
  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 *buf = skb->data;
  278. unsigned char buffer[128];
  279. unsigned int i, j;
  280. netdev_dbg(netdev, "\n************** SKB dump ****************\n");
  281. netdev_dbg(netdev, "%s packet of %d bytes\n",
  282. (tx_rx ? "TX" : "RX"), skb->len);
  283. netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest);
  284. netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source);
  285. netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
  286. for (i = 0, j = 0; i < skb->len;) {
  287. j += snprintf(buffer + j, sizeof(buffer) - j, "%02hhx",
  288. buf[i++]);
  289. if ((i % 32) == 0) {
  290. netdev_dbg(netdev, " %#06x: %s\n", i - 32, buffer);
  291. j = 0;
  292. } else if ((i % 16) == 0) {
  293. buffer[j++] = ' ';
  294. buffer[j++] = ' ';
  295. } else if ((i % 4) == 0) {
  296. buffer[j++] = ' ';
  297. }
  298. }
  299. if (i % 32)
  300. netdev_dbg(netdev, " %#06x: %s\n", i - (i % 32), buffer);
  301. netdev_dbg(netdev, "\n************** SKB dump ****************\n");
  302. }
  303. void xlgmac_get_all_hw_features(struct xlgmac_pdata *pdata)
  304. {
  305. struct xlgmac_hw_features *hw_feat = &pdata->hw_feat;
  306. unsigned int mac_hfr0, mac_hfr1, mac_hfr2;
  307. mac_hfr0 = readl(pdata->mac_regs + MAC_HWF0R);
  308. mac_hfr1 = readl(pdata->mac_regs + MAC_HWF1R);
  309. mac_hfr2 = readl(pdata->mac_regs + MAC_HWF2R);
  310. memset(hw_feat, 0, sizeof(*hw_feat));
  311. hw_feat->version = readl(pdata->mac_regs + MAC_VR);
  312. /* Hardware feature register 0 */
  313. hw_feat->phyifsel = XLGMAC_GET_REG_BITS(mac_hfr0,
  314. MAC_HWF0R_PHYIFSEL_POS,
  315. MAC_HWF0R_PHYIFSEL_LEN);
  316. hw_feat->vlhash = XLGMAC_GET_REG_BITS(mac_hfr0,
  317. MAC_HWF0R_VLHASH_POS,
  318. MAC_HWF0R_VLHASH_LEN);
  319. hw_feat->sma = XLGMAC_GET_REG_BITS(mac_hfr0,
  320. MAC_HWF0R_SMASEL_POS,
  321. MAC_HWF0R_SMASEL_LEN);
  322. hw_feat->rwk = XLGMAC_GET_REG_BITS(mac_hfr0,
  323. MAC_HWF0R_RWKSEL_POS,
  324. MAC_HWF0R_RWKSEL_LEN);
  325. hw_feat->mgk = XLGMAC_GET_REG_BITS(mac_hfr0,
  326. MAC_HWF0R_MGKSEL_POS,
  327. MAC_HWF0R_MGKSEL_LEN);
  328. hw_feat->mmc = XLGMAC_GET_REG_BITS(mac_hfr0,
  329. MAC_HWF0R_MMCSEL_POS,
  330. MAC_HWF0R_MMCSEL_LEN);
  331. hw_feat->aoe = XLGMAC_GET_REG_BITS(mac_hfr0,
  332. MAC_HWF0R_ARPOFFSEL_POS,
  333. MAC_HWF0R_ARPOFFSEL_LEN);
  334. hw_feat->ts = XLGMAC_GET_REG_BITS(mac_hfr0,
  335. MAC_HWF0R_TSSEL_POS,
  336. MAC_HWF0R_TSSEL_LEN);
  337. hw_feat->eee = XLGMAC_GET_REG_BITS(mac_hfr0,
  338. MAC_HWF0R_EEESEL_POS,
  339. MAC_HWF0R_EEESEL_LEN);
  340. hw_feat->tx_coe = XLGMAC_GET_REG_BITS(mac_hfr0,
  341. MAC_HWF0R_TXCOESEL_POS,
  342. MAC_HWF0R_TXCOESEL_LEN);
  343. hw_feat->rx_coe = XLGMAC_GET_REG_BITS(mac_hfr0,
  344. MAC_HWF0R_RXCOESEL_POS,
  345. MAC_HWF0R_RXCOESEL_LEN);
  346. hw_feat->addn_mac = XLGMAC_GET_REG_BITS(mac_hfr0,
  347. MAC_HWF0R_ADDMACADRSEL_POS,
  348. MAC_HWF0R_ADDMACADRSEL_LEN);
  349. hw_feat->ts_src = XLGMAC_GET_REG_BITS(mac_hfr0,
  350. MAC_HWF0R_TSSTSSEL_POS,
  351. MAC_HWF0R_TSSTSSEL_LEN);
  352. hw_feat->sa_vlan_ins = XLGMAC_GET_REG_BITS(mac_hfr0,
  353. MAC_HWF0R_SAVLANINS_POS,
  354. MAC_HWF0R_SAVLANINS_LEN);
  355. /* Hardware feature register 1 */
  356. hw_feat->rx_fifo_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  357. MAC_HWF1R_RXFIFOSIZE_POS,
  358. MAC_HWF1R_RXFIFOSIZE_LEN);
  359. hw_feat->tx_fifo_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  360. MAC_HWF1R_TXFIFOSIZE_POS,
  361. MAC_HWF1R_TXFIFOSIZE_LEN);
  362. hw_feat->adv_ts_hi = XLGMAC_GET_REG_BITS(mac_hfr1,
  363. MAC_HWF1R_ADVTHWORD_POS,
  364. MAC_HWF1R_ADVTHWORD_LEN);
  365. hw_feat->dma_width = XLGMAC_GET_REG_BITS(mac_hfr1,
  366. MAC_HWF1R_ADDR64_POS,
  367. MAC_HWF1R_ADDR64_LEN);
  368. hw_feat->dcb = XLGMAC_GET_REG_BITS(mac_hfr1,
  369. MAC_HWF1R_DCBEN_POS,
  370. MAC_HWF1R_DCBEN_LEN);
  371. hw_feat->sph = XLGMAC_GET_REG_BITS(mac_hfr1,
  372. MAC_HWF1R_SPHEN_POS,
  373. MAC_HWF1R_SPHEN_LEN);
  374. hw_feat->tso = XLGMAC_GET_REG_BITS(mac_hfr1,
  375. MAC_HWF1R_TSOEN_POS,
  376. MAC_HWF1R_TSOEN_LEN);
  377. hw_feat->dma_debug = XLGMAC_GET_REG_BITS(mac_hfr1,
  378. MAC_HWF1R_DBGMEMA_POS,
  379. MAC_HWF1R_DBGMEMA_LEN);
  380. hw_feat->rss = XLGMAC_GET_REG_BITS(mac_hfr1,
  381. MAC_HWF1R_RSSEN_POS,
  382. MAC_HWF1R_RSSEN_LEN);
  383. hw_feat->tc_cnt = XLGMAC_GET_REG_BITS(mac_hfr1,
  384. MAC_HWF1R_NUMTC_POS,
  385. MAC_HWF1R_NUMTC_LEN);
  386. hw_feat->hash_table_size = XLGMAC_GET_REG_BITS(mac_hfr1,
  387. MAC_HWF1R_HASHTBLSZ_POS,
  388. MAC_HWF1R_HASHTBLSZ_LEN);
  389. hw_feat->l3l4_filter_num = XLGMAC_GET_REG_BITS(mac_hfr1,
  390. MAC_HWF1R_L3L4FNUM_POS,
  391. MAC_HWF1R_L3L4FNUM_LEN);
  392. /* Hardware feature register 2 */
  393. hw_feat->rx_q_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  394. MAC_HWF2R_RXQCNT_POS,
  395. MAC_HWF2R_RXQCNT_LEN);
  396. hw_feat->tx_q_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  397. MAC_HWF2R_TXQCNT_POS,
  398. MAC_HWF2R_TXQCNT_LEN);
  399. hw_feat->rx_ch_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  400. MAC_HWF2R_RXCHCNT_POS,
  401. MAC_HWF2R_RXCHCNT_LEN);
  402. hw_feat->tx_ch_cnt = XLGMAC_GET_REG_BITS(mac_hfr2,
  403. MAC_HWF2R_TXCHCNT_POS,
  404. MAC_HWF2R_TXCHCNT_LEN);
  405. hw_feat->pps_out_num = XLGMAC_GET_REG_BITS(mac_hfr2,
  406. MAC_HWF2R_PPSOUTNUM_POS,
  407. MAC_HWF2R_PPSOUTNUM_LEN);
  408. hw_feat->aux_snap_num = XLGMAC_GET_REG_BITS(mac_hfr2,
  409. MAC_HWF2R_AUXSNAPNUM_POS,
  410. MAC_HWF2R_AUXSNAPNUM_LEN);
  411. /* Translate the Hash Table size into actual number */
  412. switch (hw_feat->hash_table_size) {
  413. case 0:
  414. break;
  415. case 1:
  416. hw_feat->hash_table_size = 64;
  417. break;
  418. case 2:
  419. hw_feat->hash_table_size = 128;
  420. break;
  421. case 3:
  422. hw_feat->hash_table_size = 256;
  423. break;
  424. }
  425. /* Translate the address width setting into actual number */
  426. switch (hw_feat->dma_width) {
  427. case 0:
  428. hw_feat->dma_width = 32;
  429. break;
  430. case 1:
  431. hw_feat->dma_width = 40;
  432. break;
  433. case 2:
  434. hw_feat->dma_width = 48;
  435. break;
  436. default:
  437. hw_feat->dma_width = 32;
  438. }
  439. /* The Queue, Channel and TC counts are zero based so increment them
  440. * to get the actual number
  441. */
  442. hw_feat->rx_q_cnt++;
  443. hw_feat->tx_q_cnt++;
  444. hw_feat->rx_ch_cnt++;
  445. hw_feat->tx_ch_cnt++;
  446. hw_feat->tc_cnt++;
  447. }
  448. void xlgmac_print_all_hw_features(struct xlgmac_pdata *pdata)
  449. {
  450. char *str = NULL;
  451. XLGMAC_PR("\n");
  452. XLGMAC_PR("=====================================================\n");
  453. XLGMAC_PR("\n");
  454. XLGMAC_PR("HW support following features\n");
  455. XLGMAC_PR("\n");
  456. /* HW Feature Register0 */
  457. XLGMAC_PR("VLAN Hash Filter Selected : %s\n",
  458. pdata->hw_feat.vlhash ? "YES" : "NO");
  459. XLGMAC_PR("SMA (MDIO) Interface : %s\n",
  460. pdata->hw_feat.sma ? "YES" : "NO");
  461. XLGMAC_PR("PMT Remote Wake-up Packet Enable : %s\n",
  462. pdata->hw_feat.rwk ? "YES" : "NO");
  463. XLGMAC_PR("PMT Magic Packet Enable : %s\n",
  464. pdata->hw_feat.mgk ? "YES" : "NO");
  465. XLGMAC_PR("RMON/MMC Module Enable : %s\n",
  466. pdata->hw_feat.mmc ? "YES" : "NO");
  467. XLGMAC_PR("ARP Offload Enabled : %s\n",
  468. pdata->hw_feat.aoe ? "YES" : "NO");
  469. XLGMAC_PR("IEEE 1588-2008 Timestamp Enabled : %s\n",
  470. pdata->hw_feat.ts ? "YES" : "NO");
  471. XLGMAC_PR("Energy Efficient Ethernet Enabled : %s\n",
  472. pdata->hw_feat.eee ? "YES" : "NO");
  473. XLGMAC_PR("Transmit Checksum Offload Enabled : %s\n",
  474. pdata->hw_feat.tx_coe ? "YES" : "NO");
  475. XLGMAC_PR("Receive Checksum Offload Enabled : %s\n",
  476. pdata->hw_feat.rx_coe ? "YES" : "NO");
  477. XLGMAC_PR("Additional MAC Addresses 1-31 Selected : %s\n",
  478. pdata->hw_feat.addn_mac ? "YES" : "NO");
  479. switch (pdata->hw_feat.ts_src) {
  480. case 0:
  481. str = "RESERVED";
  482. break;
  483. case 1:
  484. str = "INTERNAL";
  485. break;
  486. case 2:
  487. str = "EXTERNAL";
  488. break;
  489. case 3:
  490. str = "BOTH";
  491. break;
  492. }
  493. XLGMAC_PR("Timestamp System Time Source : %s\n", str);
  494. XLGMAC_PR("Source Address or VLAN Insertion Enable : %s\n",
  495. pdata->hw_feat.sa_vlan_ins ? "YES" : "NO");
  496. /* HW Feature Register1 */
  497. switch (pdata->hw_feat.rx_fifo_size) {
  498. case 0:
  499. str = "128 bytes";
  500. break;
  501. case 1:
  502. str = "256 bytes";
  503. break;
  504. case 2:
  505. str = "512 bytes";
  506. break;
  507. case 3:
  508. str = "1 KBytes";
  509. break;
  510. case 4:
  511. str = "2 KBytes";
  512. break;
  513. case 5:
  514. str = "4 KBytes";
  515. break;
  516. case 6:
  517. str = "8 KBytes";
  518. break;
  519. case 7:
  520. str = "16 KBytes";
  521. break;
  522. case 8:
  523. str = "32 kBytes";
  524. break;
  525. case 9:
  526. str = "64 KBytes";
  527. break;
  528. case 10:
  529. str = "128 KBytes";
  530. break;
  531. case 11:
  532. str = "256 KBytes";
  533. break;
  534. default:
  535. str = "RESERVED";
  536. }
  537. XLGMAC_PR("MTL Receive FIFO Size : %s\n", str);
  538. switch (pdata->hw_feat.tx_fifo_size) {
  539. case 0:
  540. str = "128 bytes";
  541. break;
  542. case 1:
  543. str = "256 bytes";
  544. break;
  545. case 2:
  546. str = "512 bytes";
  547. break;
  548. case 3:
  549. str = "1 KBytes";
  550. break;
  551. case 4:
  552. str = "2 KBytes";
  553. break;
  554. case 5:
  555. str = "4 KBytes";
  556. break;
  557. case 6:
  558. str = "8 KBytes";
  559. break;
  560. case 7:
  561. str = "16 KBytes";
  562. break;
  563. case 8:
  564. str = "32 kBytes";
  565. break;
  566. case 9:
  567. str = "64 KBytes";
  568. break;
  569. case 10:
  570. str = "128 KBytes";
  571. break;
  572. case 11:
  573. str = "256 KBytes";
  574. break;
  575. default:
  576. str = "RESERVED";
  577. }
  578. XLGMAC_PR("MTL Transmit FIFO Size : %s\n", str);
  579. XLGMAC_PR("IEEE 1588 High Word Register Enable : %s\n",
  580. pdata->hw_feat.adv_ts_hi ? "YES" : "NO");
  581. XLGMAC_PR("Address width : %u\n",
  582. pdata->hw_feat.dma_width);
  583. XLGMAC_PR("DCB Feature Enable : %s\n",
  584. pdata->hw_feat.dcb ? "YES" : "NO");
  585. XLGMAC_PR("Split Header Feature Enable : %s\n",
  586. pdata->hw_feat.sph ? "YES" : "NO");
  587. XLGMAC_PR("TCP Segmentation Offload Enable : %s\n",
  588. pdata->hw_feat.tso ? "YES" : "NO");
  589. XLGMAC_PR("DMA Debug Registers Enabled : %s\n",
  590. pdata->hw_feat.dma_debug ? "YES" : "NO");
  591. XLGMAC_PR("RSS Feature Enabled : %s\n",
  592. pdata->hw_feat.rss ? "YES" : "NO");
  593. XLGMAC_PR("Number of Traffic classes : %u\n",
  594. (pdata->hw_feat.tc_cnt));
  595. XLGMAC_PR("Hash Table Size : %u\n",
  596. pdata->hw_feat.hash_table_size);
  597. XLGMAC_PR("Total number of L3 or L4 Filters : %u\n",
  598. pdata->hw_feat.l3l4_filter_num);
  599. /* HW Feature Register2 */
  600. XLGMAC_PR("Number of MTL Receive Queues : %u\n",
  601. pdata->hw_feat.rx_q_cnt);
  602. XLGMAC_PR("Number of MTL Transmit Queues : %u\n",
  603. pdata->hw_feat.tx_q_cnt);
  604. XLGMAC_PR("Number of DMA Receive Channels : %u\n",
  605. pdata->hw_feat.rx_ch_cnt);
  606. XLGMAC_PR("Number of DMA Transmit Channels : %u\n",
  607. pdata->hw_feat.tx_ch_cnt);
  608. switch (pdata->hw_feat.pps_out_num) {
  609. case 0:
  610. str = "No PPS output";
  611. break;
  612. case 1:
  613. str = "1 PPS output";
  614. break;
  615. case 2:
  616. str = "2 PPS output";
  617. break;
  618. case 3:
  619. str = "3 PPS output";
  620. break;
  621. case 4:
  622. str = "4 PPS output";
  623. break;
  624. default:
  625. str = "RESERVED";
  626. }
  627. XLGMAC_PR("Number of PPS Outputs : %s\n", str);
  628. switch (pdata->hw_feat.aux_snap_num) {
  629. case 0:
  630. str = "No auxiliary input";
  631. break;
  632. case 1:
  633. str = "1 auxiliary input";
  634. break;
  635. case 2:
  636. str = "2 auxiliary input";
  637. break;
  638. case 3:
  639. str = "3 auxiliary input";
  640. break;
  641. case 4:
  642. str = "4 auxiliary input";
  643. break;
  644. default:
  645. str = "RESERVED";
  646. }
  647. XLGMAC_PR("Number of Auxiliary Snapshot Inputs : %s", str);
  648. XLGMAC_PR("\n");
  649. XLGMAC_PR("=====================================================\n");
  650. XLGMAC_PR("\n");
  651. }