@@ -30,6 +30,69 @@ static const struct pci_device_id igc_pci_tbl[] = {
3030
3131MODULE_DEVICE_TABLE (pci , igc_pci_tbl );
3232
33+ /* forward declaration */
34+ static int igc_sw_init (struct igc_adapter * );
35+
36+ /* PCIe configuration access */
37+ void igc_read_pci_cfg (struct igc_hw * hw , u32 reg , u16 * value )
38+ {
39+ struct igc_adapter * adapter = hw -> back ;
40+
41+ pci_read_config_word (adapter -> pdev , reg , value );
42+ }
43+
44+ void igc_write_pci_cfg (struct igc_hw * hw , u32 reg , u16 * value )
45+ {
46+ struct igc_adapter * adapter = hw -> back ;
47+
48+ pci_write_config_word (adapter -> pdev , reg , * value );
49+ }
50+
51+ s32 igc_read_pcie_cap_reg (struct igc_hw * hw , u32 reg , u16 * value )
52+ {
53+ struct igc_adapter * adapter = hw -> back ;
54+ u16 cap_offset ;
55+
56+ cap_offset = pci_find_capability (adapter -> pdev , PCI_CAP_ID_EXP );
57+ if (!cap_offset )
58+ return - IGC_ERR_CONFIG ;
59+
60+ pci_read_config_word (adapter -> pdev , cap_offset + reg , value );
61+
62+ return IGC_SUCCESS ;
63+ }
64+
65+ s32 igc_write_pcie_cap_reg (struct igc_hw * hw , u32 reg , u16 * value )
66+ {
67+ struct igc_adapter * adapter = hw -> back ;
68+ u16 cap_offset ;
69+
70+ cap_offset = pci_find_capability (adapter -> pdev , PCI_CAP_ID_EXP );
71+ if (!cap_offset )
72+ return - IGC_ERR_CONFIG ;
73+
74+ pci_write_config_word (adapter -> pdev , cap_offset + reg , * value );
75+
76+ return IGC_SUCCESS ;
77+ }
78+
79+ u32 igc_rd32 (struct igc_hw * hw , u32 reg )
80+ {
81+ u8 __iomem * hw_addr = READ_ONCE (hw -> hw_addr );
82+ u32 value = 0 ;
83+
84+ if (IGC_REMOVED (hw_addr ))
85+ return ~value ;
86+
87+ value = readl (& hw_addr [reg ]);
88+
89+ /* reads should not return all F's */
90+ if (!(~value ) && (!reg || !(~readl (hw_addr ))))
91+ hw -> hw_addr = NULL ;
92+
93+ return value ;
94+ }
95+
3396/**
3497 * igc_probe - Device Initialization Routine
3598 * @pdev: PCI device information struct
@@ -44,6 +107,7 @@ MODULE_DEVICE_TABLE(pci, igc_pci_tbl);
44107static int igc_probe (struct pci_dev * pdev ,
45108 const struct pci_device_id * ent )
46109{
110+ struct igc_adapter * adapter ;
47111 int err , pci_using_dac ;
48112
49113 err = pci_enable_device_mem (pdev );
@@ -78,8 +142,15 @@ static int igc_probe(struct pci_dev *pdev,
78142
79143 pci_set_master (pdev );
80144 err = pci_save_state (pdev );
145+
146+ /* setup the private structure */
147+ err = igc_sw_init (adapter );
148+ if (err )
149+ goto err_sw_init ;
150+
81151 return 0 ;
82152
153+ err_sw_init :
83154err_pci_reg :
84155err_dma :
85156 pci_disable_device (pdev );
@@ -110,6 +181,33 @@ static struct pci_driver igc_driver = {
110181 .remove = igc_remove ,
111182};
112183
184+ /**
185+ * igc_sw_init - Initialize general software structures (struct igc_adapter)
186+ * @adapter: board private structure to initialize
187+ *
188+ * igc_sw_init initializes the Adapter private data structure.
189+ * Fields are initialized based on PCI device information and
190+ * OS network device settings (MTU size).
191+ */
192+ static int igc_sw_init (struct igc_adapter * adapter )
193+ {
194+ struct pci_dev * pdev = adapter -> pdev ;
195+ struct igc_hw * hw = & adapter -> hw ;
196+
197+ /* PCI config space info */
198+
199+ hw -> vendor_id = pdev -> vendor ;
200+ hw -> device_id = pdev -> device ;
201+ hw -> subsystem_vendor_id = pdev -> subsystem_vendor ;
202+ hw -> subsystem_device_id = pdev -> subsystem_device ;
203+
204+ pci_read_config_byte (pdev , PCI_REVISION_ID , & hw -> revision_id );
205+
206+ pci_read_config_word (pdev , PCI_COMMAND , & hw -> bus .pci_cmd_word );
207+
208+ return 0 ;
209+ }
210+
113211/**
114212 * igc_init_module - Driver Registration Routine
115213 *
0 commit comments