|
4 | 4 | #ifndef _IDPF_H_
|
5 | 5 | #define _IDPF_H_
|
6 | 6 |
|
| 7 | +/* Forward declaration */ |
| 8 | +struct idpf_adapter; |
| 9 | + |
7 | 10 | #include <linux/aer.h>
|
8 | 11 | #include <linux/etherdevice.h>
|
9 | 12 | #include <linux/pci.h>
|
10 | 13 |
|
11 | 14 | #include "idpf_controlq.h"
|
12 | 15 |
|
| 16 | +/* Default Mailbox settings */ |
| 17 | +#define IDPF_NUM_DFLT_MBX_Q 2 /* includes both TX and RX */ |
| 18 | +#define IDPF_DFLT_MBX_Q_LEN 64 |
| 19 | +#define IDPF_DFLT_MBX_ID -1 |
| 20 | + |
13 | 21 | /* available message levels */
|
14 | 22 | #define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
|
15 | 23 |
|
| 24 | +/** |
| 25 | + * enum idpf_state - State machine to handle bring up |
| 26 | + * @__IDPF_STARTUP: Start the state machine |
| 27 | + * @__IDPF_STATE_LAST: Must be last, used to determine size |
| 28 | + */ |
| 29 | +enum idpf_state { |
| 30 | + __IDPF_STARTUP, |
| 31 | + __IDPF_STATE_LAST, |
| 32 | +}; |
| 33 | + |
| 34 | +/** |
| 35 | + * enum idpf_flags - Hard reset causes. |
| 36 | + * @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout |
| 37 | + * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW |
| 38 | + * @IDPF_HR_RESET_IN_PROG: Reset in progress |
| 39 | + * @IDPF_REMOVE_IN_PROG: Driver remove in progress |
| 40 | + * @IDPF_FLAGS_NBITS: Must be last |
| 41 | + */ |
| 42 | +enum idpf_flags { |
| 43 | + IDPF_HR_FUNC_RESET, |
| 44 | + IDPF_HR_DRV_LOAD, |
| 45 | + IDPF_HR_RESET_IN_PROG, |
| 46 | + IDPF_REMOVE_IN_PROG, |
| 47 | + IDPF_FLAGS_NBITS, |
| 48 | +}; |
| 49 | + |
| 50 | +/** |
| 51 | + * struct idpf_reset_reg - Reset register offsets/masks |
| 52 | + * @rstat: Reset status register |
| 53 | + * @rstat_m: Reset status mask |
| 54 | + */ |
| 55 | +struct idpf_reset_reg { |
| 56 | + void __iomem *rstat; |
| 57 | + u32 rstat_m; |
| 58 | +}; |
| 59 | + |
| 60 | +/** |
| 61 | + * struct idpf_reg_ops - Device specific register operation function pointers |
| 62 | + * @ctlq_reg_init: Mailbox control queue register initialization |
| 63 | + * @reset_reg_init: Reset register initialization |
| 64 | + * @trigger_reset: Trigger a reset to occur |
| 65 | + */ |
| 66 | +struct idpf_reg_ops { |
| 67 | + void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq); |
| 68 | + void (*reset_reg_init)(struct idpf_adapter *adapter); |
| 69 | + void (*trigger_reset)(struct idpf_adapter *adapter, |
| 70 | + enum idpf_flags trig_cause); |
| 71 | +}; |
| 72 | + |
| 73 | +/** |
| 74 | + * struct idpf_dev_ops - Device specific operations |
| 75 | + * @reg_ops: Register operations |
| 76 | + */ |
| 77 | +struct idpf_dev_ops { |
| 78 | + struct idpf_reg_ops reg_ops; |
| 79 | +}; |
| 80 | + |
16 | 81 | /**
|
17 | 82 | * struct idpf_adapter - Device data struct generated on probe
|
18 | 83 | * @pdev: PCI device struct given on probe
|
19 | 84 | * @msg_enable: Debug message level enabled
|
| 85 | + * @state: Init state machine |
| 86 | + * @flags: See enum idpf_flags |
| 87 | + * @reset_reg: See struct idpf_reset_reg |
20 | 88 | * @hw: Device access data
|
| 89 | + * @vc_event_task: Task to handle out of band virtchnl event notifications |
| 90 | + * @vc_event_wq: Workqueue for virtchnl events |
| 91 | + * @dev_ops: See idpf_dev_ops |
| 92 | + * @vport_ctrl_lock: Lock to protect the vport control flow |
21 | 93 | */
|
22 | 94 | struct idpf_adapter {
|
23 | 95 | struct pci_dev *pdev;
|
24 | 96 | u32 msg_enable;
|
| 97 | + enum idpf_state state; |
| 98 | + DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS); |
| 99 | + struct idpf_reset_reg reset_reg; |
25 | 100 | struct idpf_hw hw;
|
| 101 | + |
| 102 | + struct delayed_work vc_event_task; |
| 103 | + struct workqueue_struct *vc_event_wq; |
| 104 | + |
| 105 | + struct idpf_dev_ops dev_ops; |
| 106 | + |
| 107 | + struct mutex vport_ctrl_lock; |
26 | 108 | };
|
27 | 109 |
|
| 110 | +/** |
| 111 | + * idpf_get_reg_addr - Get BAR0 register address |
| 112 | + * @adapter: private data struct |
| 113 | + * @reg_offset: register offset value |
| 114 | + * |
| 115 | + * Based on the register offset, return the actual BAR0 register address |
| 116 | + */ |
| 117 | +static inline void __iomem *idpf_get_reg_addr(struct idpf_adapter *adapter, |
| 118 | + resource_size_t reg_offset) |
| 119 | +{ |
| 120 | + return (void __iomem *)(adapter->hw.hw_addr + reg_offset); |
| 121 | +} |
| 122 | + |
| 123 | +/** |
| 124 | + * idpf_is_reset_detected - check if we were reset at some point |
| 125 | + * @adapter: driver specific private structure |
| 126 | + * |
| 127 | + * Returns true if we are either in reset currently or were previously reset. |
| 128 | + */ |
| 129 | +static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter) |
| 130 | +{ |
| 131 | + if (!adapter->hw.arq) |
| 132 | + return true; |
| 133 | + |
| 134 | + return !(readl(idpf_get_reg_addr(adapter, adapter->hw.arq->reg.len)) & |
| 135 | + adapter->hw.arq->reg.len_mask); |
| 136 | +} |
| 137 | + |
| 138 | +void idpf_vc_event_task(struct work_struct *work); |
| 139 | +void idpf_dev_ops_init(struct idpf_adapter *adapter); |
| 140 | +void idpf_vf_dev_ops_init(struct idpf_adapter *adapter); |
| 141 | +int idpf_init_dflt_mbx(struct idpf_adapter *adapter); |
| 142 | +void idpf_deinit_dflt_mbx(struct idpf_adapter *adapter); |
| 143 | + |
28 | 144 | #endif /* !_IDPF_H_ */
|
0 commit comments