Skip to content

Commit 146740f

Browse files
aneftinJeff Kirsher
authored andcommitted
igc: Add support for PF
This patch adds the basic defines and structures needed by the PF for operation. With this it is possible to bring up the interface, but without being able to configure any of the filters on the interface itself. Add skeleton for a function pointers. Signed-off-by: Sasha Neftin <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent d89f884 commit 146740f

File tree

9 files changed

+442
-1
lines changed

9 files changed

+442
-1
lines changed

drivers/net/ethernet/intel/igc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
obj-$(CONFIG_IGC) += igc.o
99

10-
igc-objs := igc_main.o
10+
igc-objs := igc_main.o igc_mac.o

drivers/net/ethernet/intel/igc/igc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@
2222
#include <linux/net_tstamp.h>
2323
#include <linux/ptp_clock_kernel.h>
2424

25+
#include "igc_hw.h"
26+
2527
/* main */
2628
extern char igc_driver_name[];
2729
extern char igc_driver_version[];
2830

31+
/* Board specific private data structure */
32+
struct igc_adapter {
33+
u8 __iomem *io_addr;
34+
35+
/* OS defined structs */
36+
struct pci_dev *pdev;
37+
38+
/* structs defined in igc_hw.h */
39+
struct igc_hw hw;
40+
};
41+
2942
#endif /* _IGC_H_ */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (c) 2018 Intel Corporation */
3+
4+
#ifndef _IGC_DEFINES_H_
5+
#define _IGC_DEFINES_H_
6+
7+
/* PCI Bus Info */
8+
#define PCIE_DEVICE_CONTROL2 0x28
9+
#define PCIE_DEVICE_CONTROL2_16ms 0x0005
10+
11+
/* Error Codes */
12+
#define IGC_SUCCESS 0
13+
#define IGC_ERR_NVM 1
14+
#define IGC_ERR_PHY 2
15+
#define IGC_ERR_CONFIG 3
16+
#define IGC_ERR_PARAM 4
17+
#define IGC_ERR_MAC_INIT 5
18+
#define IGC_ERR_RESET 9
19+
20+
/* Device Status */
21+
#define IGC_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */
22+
#define IGC_STATUS_LU 0x00000002 /* Link up.0=no,1=link */
23+
#define IGC_STATUS_FUNC_MASK 0x0000000C /* PCI Function Mask */
24+
#define IGC_STATUS_FUNC_SHIFT 2
25+
#define IGC_STATUS_FUNC_1 0x00000004 /* Function 1 */
26+
#define IGC_STATUS_TXOFF 0x00000010 /* transmission paused */
27+
#define IGC_STATUS_SPEED_100 0x00000040 /* Speed 100Mb/s */
28+
#define IGC_STATUS_SPEED_1000 0x00000080 /* Speed 1000Mb/s */
29+
30+
#endif /* _IGC_DEFINES_H_ */

drivers/net/ethernet/intel/igc/igc_hw.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,89 @@
44
#ifndef _IGC_HW_H_
55
#define _IGC_HW_H_
66

7+
#include <linux/types.h>
8+
#include <linux/if_ether.h>
9+
#include "igc_regs.h"
10+
#include "igc_defines.h"
11+
#include "igc_mac.h"
12+
#include "igc_i225.h"
13+
714
#define IGC_DEV_ID_I225_LM 0x15F2
815
#define IGC_DEV_ID_I225_V 0x15F3
916

17+
/* Function pointers for the MAC. */
18+
struct igc_mac_operations {
19+
};
20+
21+
enum igc_mac_type {
22+
igc_undefined = 0,
23+
igc_i225,
24+
igc_num_macs /* List is 1-based, so subtract 1 for true count. */
25+
};
26+
27+
enum igc_phy_type {
28+
igc_phy_unknown = 0,
29+
igc_phy_none,
30+
igc_phy_i225,
31+
};
32+
33+
struct igc_mac_info {
34+
struct igc_mac_operations ops;
35+
36+
u8 addr[ETH_ALEN];
37+
u8 perm_addr[ETH_ALEN];
38+
39+
enum igc_mac_type type;
40+
41+
u32 collision_delta;
42+
u32 ledctl_default;
43+
u32 ledctl_mode1;
44+
u32 ledctl_mode2;
45+
u32 mc_filter_type;
46+
u32 tx_packet_delta;
47+
u32 txcw;
48+
49+
u16 mta_reg_count;
50+
u16 uta_reg_count;
51+
52+
u16 rar_entry_count;
53+
54+
u8 forced_speed_duplex;
55+
56+
bool adaptive_ifs;
57+
bool has_fwsm;
58+
bool arc_subsystem_valid;
59+
60+
bool autoneg;
61+
bool autoneg_failed;
62+
};
63+
64+
struct igc_bus_info {
65+
u16 func;
66+
u16 pci_cmd_word;
67+
};
68+
69+
struct igc_hw {
70+
void *back;
71+
72+
u8 __iomem *hw_addr;
73+
unsigned long io_base;
74+
75+
struct igc_mac_info mac;
76+
77+
struct igc_bus_info bus;
78+
79+
u16 device_id;
80+
u16 subsystem_vendor_id;
81+
u16 subsystem_device_id;
82+
u16 vendor_id;
83+
84+
u8 revision_id;
85+
};
86+
87+
s32 igc_read_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value);
88+
s32 igc_write_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value);
89+
void igc_read_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value);
90+
void igc_write_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value);
91+
1092
#endif /* _IGC_HW_H_ */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (c) 2018 Intel Corporation */
3+
4+
#ifndef _IGC_I225_H_
5+
#define _IGC_I225_H_
6+
7+
s32 igc_acquire_swfw_sync_i225(struct igc_hw *hw, u16 mask);
8+
void igc_release_swfw_sync_i225(struct igc_hw *hw, u16 mask);
9+
10+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2018 Intel Corporation */
3+
4+
#include <linux/pci.h>
5+
#include "igc_hw.h"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (c) 2018 Intel Corporation */
3+
4+
#ifndef _IGC_MAC_H_
5+
#define _IGC_MAC_H_
6+
7+
#ifndef IGC_REMOVED
8+
#define IGC_REMOVED(a) (0)
9+
#endif /* IGC_REMOVED */
10+
11+
#endif

drivers/net/ethernet/intel/igc/igc_main.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,69 @@ static const struct pci_device_id igc_pci_tbl[] = {
3030

3131
MODULE_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);
44107
static 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:
83154
err_pci_reg:
84155
err_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

Comments
 (0)