1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4  *
5  * Based on the r8180 driver, which is:
6  * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
7  *
8  * Contact Information: wlanfae <wlanfae@realtek.com>
9  */
10 #include "rtl_pci.h"
11 #include "rtl_core.h"
12 
_rtl92e_parse_pci_configuration(struct pci_dev * pdev,struct net_device * dev)13 static void _rtl92e_parse_pci_configuration(struct pci_dev *pdev,
14 					    struct net_device *dev)
15 {
16 	struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
17 
18 	u8 tmp;
19 	u16 link_ctrl_reg;
20 
21 	pcie_capability_read_word(priv->pdev, PCI_EXP_LNKCTL, &link_ctrl_reg);
22 
23 	pci_read_config_byte(pdev, 0x98, &tmp);
24 	tmp |= BIT4;
25 	pci_write_config_byte(pdev, 0x98, tmp);
26 
27 	tmp = 0x17;
28 	pci_write_config_byte(pdev, 0x70f, tmp);
29 }
30 
rtl92e_check_adapter(struct pci_dev * pdev,struct net_device * dev)31 bool rtl92e_check_adapter(struct pci_dev *pdev, struct net_device *dev)
32 {
33 	struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
34 	u16 device_id;
35 	u8  revision_id;
36 	u16 irq_line;
37 
38 	device_id = pdev->device;
39 	revision_id = pdev->revision;
40 	pci_read_config_word(pdev, 0x3C, &irq_line);
41 
42 	priv->card_8192 = NIC_8192E;
43 
44 	if (device_id == 0x8192) {
45 		switch (revision_id) {
46 		case HAL_HW_PCI_REVISION_ID_8192PCIE:
47 			dev_info(&pdev->dev,
48 				 "Adapter(8192 PCI-E) is found - DeviceID=%x\n",
49 				 device_id);
50 			priv->card_8192 = NIC_8192E;
51 			break;
52 		case HAL_HW_PCI_REVISION_ID_8192SE:
53 			dev_info(&pdev->dev,
54 				 "Adapter(8192SE) is found - DeviceID=%x\n",
55 				 device_id);
56 			priv->card_8192 = NIC_8192SE;
57 			break;
58 		default:
59 			dev_info(&pdev->dev,
60 				 "UNKNOWN nic type(%4x:%4x)\n",
61 				 pdev->vendor, pdev->device);
62 			priv->card_8192 = NIC_UNKNOWN;
63 			return false;
64 		}
65 	}
66 
67 	if (priv->card_8192 != NIC_8192E) {
68 		dev_info(&pdev->dev,
69 			 "Detect info(%x) and hardware info(%x) not match!\n",
70 			 NIC_8192E, priv->card_8192);
71 		dev_info(&pdev->dev,
72 			 "Please select proper driver before install!!!!\n");
73 		return false;
74 	}
75 
76 	_rtl92e_parse_pci_configuration(pdev, dev);
77 
78 	return true;
79 }
80