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 LinkCtrlReg;
20 
21 	pcie_capability_read_word(priv->pdev, PCI_EXP_LNKCTL, &LinkCtrlReg);
22 
23 	RT_TRACE(COMP_INIT, "Link Control Register =%x\n", LinkCtrlReg);
24 
25 	pci_read_config_byte(pdev, 0x98, &tmp);
26 	tmp |= BIT4;
27 	pci_write_config_byte(pdev, 0x98, tmp);
28 
29 	tmp = 0x17;
30 	pci_write_config_byte(pdev, 0x70f, tmp);
31 }
32 
rtl92e_check_adapter(struct pci_dev * pdev,struct net_device * dev)33 bool rtl92e_check_adapter(struct pci_dev *pdev, struct net_device *dev)
34 {
35 	struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
36 	u16 DeviceID;
37 	u8  RevisionID;
38 	u16 IrqLine;
39 
40 	DeviceID = pdev->device;
41 	RevisionID = pdev->revision;
42 	pci_read_config_word(pdev, 0x3C, &IrqLine);
43 
44 	priv->card_8192 = priv->ops->nic_type;
45 
46 	if (DeviceID == 0x8192) {
47 		switch (RevisionID) {
48 		case HAL_HW_PCI_REVISION_ID_8192PCIE:
49 			dev_info(&pdev->dev,
50 				 "Adapter(8192 PCI-E) is found - DeviceID=%x\n",
51 				 DeviceID);
52 			priv->card_8192 = NIC_8192E;
53 			break;
54 		case HAL_HW_PCI_REVISION_ID_8192SE:
55 			dev_info(&pdev->dev,
56 				 "Adapter(8192SE) is found - DeviceID=%x\n",
57 				 DeviceID);
58 			priv->card_8192 = NIC_8192SE;
59 			break;
60 		default:
61 			dev_info(&pdev->dev,
62 				 "UNKNOWN nic type(%4x:%4x)\n",
63 				 pdev->vendor, pdev->device);
64 			priv->card_8192 = NIC_UNKNOWN;
65 			return false;
66 		}
67 	}
68 
69 	if (priv->ops->nic_type != priv->card_8192) {
70 		dev_info(&pdev->dev,
71 			 "Detect info(%x) and hardware info(%x) not match!\n",
72 			 priv->ops->nic_type, priv->card_8192);
73 		dev_info(&pdev->dev,
74 			 "Please select proper driver before install!!!!\n");
75 		return false;
76 	}
77 
78 	_rtl92e_parse_pci_configuration(pdev, dev);
79 
80 	return true;
81 }
82