| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - This program is free software; you can redistribute it and/or |
|---|
| 3 | | - modify it under the terms of the GNU General Public License |
|---|
| 4 | | - as published by the Free Software Foundation; either version 2 |
|---|
| 5 | | - of the License, or (at your option) any later version. |
|---|
| 6 | | - |
|---|
| 7 | | - This program is distributed in the hope that it will be useful, |
|---|
| 8 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 9 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 10 | | - GNU General Public License for more details. |
|---|
| 11 | 3 | |
|---|
| 12 | 4 | |
|---|
| 13 | 5 | */ |
|---|
| .. | .. |
|---|
| 15 | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 16 | 8 | |
|---|
| 17 | 9 | #define DRV_NAME "uli526x" |
|---|
| 18 | | -#define DRV_VERSION "0.9.3" |
|---|
| 19 | | -#define DRV_RELDATE "2005-7-29" |
|---|
| 20 | 10 | |
|---|
| 21 | 11 | #include <linux/module.h> |
|---|
| 22 | 12 | |
|---|
| .. | .. |
|---|
| 204 | 194 | }; |
|---|
| 205 | 195 | |
|---|
| 206 | 196 | /* Global variable declaration ----------------------------- */ |
|---|
| 207 | | -static int printed_version; |
|---|
| 208 | | -static const char version[] = |
|---|
| 209 | | - "ULi M5261/M5263 net driver, version " DRV_VERSION " (" DRV_RELDATE ")"; |
|---|
| 210 | | - |
|---|
| 211 | 197 | static int uli526x_debug; |
|---|
| 212 | 198 | static unsigned char uli526x_media_mode = ULI526X_AUTO; |
|---|
| 213 | 199 | static u32 uli526x_cr6_user_set; |
|---|
| .. | .. |
|---|
| 290 | 276 | |
|---|
| 291 | 277 | ULI526X_DBUG(0, "uli526x_init_one()", 0); |
|---|
| 292 | 278 | |
|---|
| 293 | | - if (!printed_version++) |
|---|
| 294 | | - pr_info("%s\n", version); |
|---|
| 295 | | - |
|---|
| 296 | 279 | /* Init network device */ |
|---|
| 297 | 280 | dev = alloc_etherdev(sizeof(*db)); |
|---|
| 298 | 281 | if (dev == NULL) |
|---|
| 299 | 282 | return -ENOMEM; |
|---|
| 300 | 283 | SET_NETDEV_DEV(dev, &pdev->dev); |
|---|
| 301 | 284 | |
|---|
| 302 | | - if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
|---|
| 285 | + if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { |
|---|
| 303 | 286 | pr_warn("32-bit PCI DMA not available\n"); |
|---|
| 304 | 287 | err = -ENODEV; |
|---|
| 305 | 288 | goto err_out_free; |
|---|
| .. | .. |
|---|
| 334 | 317 | /* Allocate Tx/Rx descriptor memory */ |
|---|
| 335 | 318 | err = -ENOMEM; |
|---|
| 336 | 319 | |
|---|
| 337 | | - db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr); |
|---|
| 320 | + db->desc_pool_ptr = dma_alloc_coherent(&pdev->dev, |
|---|
| 321 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 322 | + &db->desc_pool_dma_ptr, GFP_KERNEL); |
|---|
| 338 | 323 | if (!db->desc_pool_ptr) |
|---|
| 339 | 324 | goto err_out_release; |
|---|
| 340 | 325 | |
|---|
| 341 | | - db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, &db->buf_pool_dma_ptr); |
|---|
| 326 | + db->buf_pool_ptr = dma_alloc_coherent(&pdev->dev, |
|---|
| 327 | + TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 328 | + &db->buf_pool_dma_ptr, GFP_KERNEL); |
|---|
| 342 | 329 | if (!db->buf_pool_ptr) |
|---|
| 343 | 330 | goto err_out_free_tx_desc; |
|---|
| 344 | 331 | |
|---|
| .. | .. |
|---|
| 418 | 405 | err_out_unmap: |
|---|
| 419 | 406 | pci_iounmap(pdev, db->ioaddr); |
|---|
| 420 | 407 | err_out_free_tx_buf: |
|---|
| 421 | | - pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 422 | | - db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 408 | + dma_free_coherent(&pdev->dev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 409 | + db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 423 | 410 | err_out_free_tx_desc: |
|---|
| 424 | | - pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 425 | | - db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 411 | + dma_free_coherent(&pdev->dev, |
|---|
| 412 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 413 | + db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 426 | 414 | err_out_release: |
|---|
| 427 | 415 | pci_release_regions(pdev); |
|---|
| 428 | 416 | err_out_disable: |
|---|
| .. | .. |
|---|
| 441 | 429 | |
|---|
| 442 | 430 | unregister_netdev(dev); |
|---|
| 443 | 431 | pci_iounmap(pdev, db->ioaddr); |
|---|
| 444 | | - pci_free_consistent(db->pdev, sizeof(struct tx_desc) * |
|---|
| 445 | | - DESC_ALL_CNT + 0x20, db->desc_pool_ptr, |
|---|
| 446 | | - db->desc_pool_dma_ptr); |
|---|
| 447 | | - pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 448 | | - db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 432 | + dma_free_coherent(&db->pdev->dev, |
|---|
| 433 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 434 | + db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 435 | + dma_free_coherent(&db->pdev->dev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 436 | + db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 449 | 437 | pci_release_regions(pdev); |
|---|
| 450 | 438 | pci_disable_device(pdev); |
|---|
| 451 | 439 | free_netdev(dev); |
|---|
| .. | .. |
|---|
| 827 | 815 | db->rx_avail_cnt--; |
|---|
| 828 | 816 | db->interval_rx_cnt++; |
|---|
| 829 | 817 | |
|---|
| 830 | | - pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2), RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE); |
|---|
| 818 | + dma_unmap_single(&db->pdev->dev, le32_to_cpu(rxptr->rdes2), |
|---|
| 819 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE); |
|---|
| 831 | 820 | if ( (rdes0 & 0x300) != 0x300) { |
|---|
| 832 | 821 | /* A packet without First/Last flag */ |
|---|
| 833 | 822 | /* reuse this SKB */ |
|---|
| .. | .. |
|---|
| 980 | 969 | struct uli526x_board_info *np = netdev_priv(dev); |
|---|
| 981 | 970 | |
|---|
| 982 | 971 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
|---|
| 983 | | - strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
|---|
| 984 | 972 | strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info)); |
|---|
| 985 | 973 | } |
|---|
| 986 | 974 | |
|---|
| .. | .. |
|---|
| 1181 | 1169 | netif_wake_queue(dev); |
|---|
| 1182 | 1170 | } |
|---|
| 1183 | 1171 | |
|---|
| 1184 | | - |
|---|
| 1185 | | -#ifdef CONFIG_PM |
|---|
| 1186 | | - |
|---|
| 1187 | 1172 | /* |
|---|
| 1188 | 1173 | * Suspend the interface. |
|---|
| 1189 | 1174 | */ |
|---|
| 1190 | 1175 | |
|---|
| 1191 | | -static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state) |
|---|
| 1176 | +static int __maybe_unused uli526x_suspend(struct device *dev_d) |
|---|
| 1192 | 1177 | { |
|---|
| 1193 | | - struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 1194 | | - pci_power_t power_state; |
|---|
| 1195 | | - int err; |
|---|
| 1178 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 1196 | 1179 | |
|---|
| 1197 | 1180 | ULI526X_DBUG(0, "uli526x_suspend", 0); |
|---|
| 1198 | | - |
|---|
| 1199 | | - pci_save_state(pdev); |
|---|
| 1200 | 1181 | |
|---|
| 1201 | 1182 | if (!netif_running(dev)) |
|---|
| 1202 | 1183 | return 0; |
|---|
| .. | .. |
|---|
| 1204 | 1185 | netif_device_detach(dev); |
|---|
| 1205 | 1186 | uli526x_reset_prepare(dev); |
|---|
| 1206 | 1187 | |
|---|
| 1207 | | - power_state = pci_choose_state(pdev, state); |
|---|
| 1208 | | - pci_enable_wake(pdev, power_state, 0); |
|---|
| 1209 | | - err = pci_set_power_state(pdev, power_state); |
|---|
| 1210 | | - if (err) { |
|---|
| 1211 | | - netif_device_attach(dev); |
|---|
| 1212 | | - /* Re-initialize ULI526X board */ |
|---|
| 1213 | | - uli526x_init(dev); |
|---|
| 1214 | | - /* Restart upper layer interface */ |
|---|
| 1215 | | - netif_wake_queue(dev); |
|---|
| 1216 | | - } |
|---|
| 1188 | + device_set_wakeup_enable(dev_d, 0); |
|---|
| 1217 | 1189 | |
|---|
| 1218 | | - return err; |
|---|
| 1190 | + return 0; |
|---|
| 1219 | 1191 | } |
|---|
| 1220 | 1192 | |
|---|
| 1221 | 1193 | /* |
|---|
| 1222 | 1194 | * Resume the interface. |
|---|
| 1223 | 1195 | */ |
|---|
| 1224 | 1196 | |
|---|
| 1225 | | -static int uli526x_resume(struct pci_dev *pdev) |
|---|
| 1197 | +static int __maybe_unused uli526x_resume(struct device *dev_d) |
|---|
| 1226 | 1198 | { |
|---|
| 1227 | | - struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 1228 | | - int err; |
|---|
| 1199 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 1229 | 1200 | |
|---|
| 1230 | 1201 | ULI526X_DBUG(0, "uli526x_resume", 0); |
|---|
| 1231 | 1202 | |
|---|
| 1232 | | - pci_restore_state(pdev); |
|---|
| 1233 | 1203 | |
|---|
| 1234 | 1204 | if (!netif_running(dev)) |
|---|
| 1235 | 1205 | return 0; |
|---|
| 1236 | | - |
|---|
| 1237 | | - err = pci_set_power_state(pdev, PCI_D0); |
|---|
| 1238 | | - if (err) { |
|---|
| 1239 | | - netdev_warn(dev, "Could not put device into D0\n"); |
|---|
| 1240 | | - return err; |
|---|
| 1241 | | - } |
|---|
| 1242 | 1206 | |
|---|
| 1243 | 1207 | netif_device_attach(dev); |
|---|
| 1244 | 1208 | /* Re-initialize ULI526X board */ |
|---|
| .. | .. |
|---|
| 1248 | 1212 | |
|---|
| 1249 | 1213 | return 0; |
|---|
| 1250 | 1214 | } |
|---|
| 1251 | | - |
|---|
| 1252 | | -#else /* !CONFIG_PM */ |
|---|
| 1253 | | - |
|---|
| 1254 | | -#define uli526x_suspend NULL |
|---|
| 1255 | | -#define uli526x_resume NULL |
|---|
| 1256 | | - |
|---|
| 1257 | | -#endif /* !CONFIG_PM */ |
|---|
| 1258 | | - |
|---|
| 1259 | 1215 | |
|---|
| 1260 | 1216 | /* |
|---|
| 1261 | 1217 | * free all allocated rx buffer |
|---|
| .. | .. |
|---|
| 1284 | 1240 | |
|---|
| 1285 | 1241 | if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) { |
|---|
| 1286 | 1242 | rxptr->rx_skb_ptr = skb; |
|---|
| 1287 | | - rxptr->rdes2 = cpu_to_le32(pci_map_single(db->pdev, |
|---|
| 1288 | | - skb_tail_pointer(skb), |
|---|
| 1289 | | - RX_ALLOC_SIZE, |
|---|
| 1290 | | - PCI_DMA_FROMDEVICE)); |
|---|
| 1243 | + rxptr->rdes2 = cpu_to_le32(dma_map_single(&db->pdev->dev, skb_tail_pointer(skb), |
|---|
| 1244 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE)); |
|---|
| 1291 | 1245 | wmb(); |
|---|
| 1292 | 1246 | rxptr->rdes0 = cpu_to_le32(0x80000000); |
|---|
| 1293 | 1247 | db->rx_avail_cnt++; |
|---|
| .. | .. |
|---|
| 1459 | 1413 | if (skb == NULL) |
|---|
| 1460 | 1414 | break; |
|---|
| 1461 | 1415 | rxptr->rx_skb_ptr = skb; /* FIXME (?) */ |
|---|
| 1462 | | - rxptr->rdes2 = cpu_to_le32(pci_map_single(db->pdev, |
|---|
| 1463 | | - skb_tail_pointer(skb), |
|---|
| 1464 | | - RX_ALLOC_SIZE, |
|---|
| 1465 | | - PCI_DMA_FROMDEVICE)); |
|---|
| 1416 | + rxptr->rdes2 = cpu_to_le32(dma_map_single(&db->pdev->dev, skb_tail_pointer(skb), |
|---|
| 1417 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE)); |
|---|
| 1466 | 1418 | wmb(); |
|---|
| 1467 | 1419 | rxptr->rdes0 = cpu_to_le32(0x80000000); |
|---|
| 1468 | 1420 | rxptr = rxptr->next_rx_desc; |
|---|
| .. | .. |
|---|
| 1779 | 1731 | }; |
|---|
| 1780 | 1732 | MODULE_DEVICE_TABLE(pci, uli526x_pci_tbl); |
|---|
| 1781 | 1733 | |
|---|
| 1734 | +static SIMPLE_DEV_PM_OPS(uli526x_pm_ops, uli526x_suspend, uli526x_resume); |
|---|
| 1782 | 1735 | |
|---|
| 1783 | 1736 | static struct pci_driver uli526x_driver = { |
|---|
| 1784 | 1737 | .name = "uli526x", |
|---|
| 1785 | 1738 | .id_table = uli526x_pci_tbl, |
|---|
| 1786 | 1739 | .probe = uli526x_init_one, |
|---|
| 1787 | 1740 | .remove = uli526x_remove_one, |
|---|
| 1788 | | - .suspend = uli526x_suspend, |
|---|
| 1789 | | - .resume = uli526x_resume, |
|---|
| 1741 | + .driver.pm = &uli526x_pm_ops, |
|---|
| 1790 | 1742 | }; |
|---|
| 1791 | 1743 | |
|---|
| 1792 | 1744 | MODULE_AUTHOR("Peer Chen, peer.chen@uli.com.tw"); |
|---|
| .. | .. |
|---|
| 1806 | 1758 | |
|---|
| 1807 | 1759 | static int __init uli526x_init_module(void) |
|---|
| 1808 | 1760 | { |
|---|
| 1809 | | - |
|---|
| 1810 | | - pr_info("%s\n", version); |
|---|
| 1811 | | - printed_version = 1; |
|---|
| 1812 | 1761 | |
|---|
| 1813 | 1762 | ULI526X_DBUG(0, "init_module() ", debug); |
|---|
| 1814 | 1763 | |
|---|