Commit 0a6e5008a9df678b48f8d4e57601aa4270df6c14

Authored by Ben Hutchings
1 parent 9724a8504c

sfc: Fix MCDI structure field lookup

The least significant bit number (LBN) of a field within an MCDI
structure is counted from the start of the structure, not the
containing dword.  In MCDI_ARRAY_FIELD() we need to mask it rather
than using the usual EFX_DWORD_FIELD() macro.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>

Showing 1 changed file with 4 additions and 2 deletions Inline Diff

drivers/net/ethernet/sfc/mcdi.h
1 /**************************************************************************** 1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards 2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2008-2010 Solarflare Communications Inc. 3 * Copyright 2008-2010 Solarflare Communications Inc.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published 6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference. 7 * by the Free Software Foundation, incorporated herein by reference.
8 */ 8 */
9 9
10 #ifndef EFX_MCDI_H 10 #ifndef EFX_MCDI_H
11 #define EFX_MCDI_H 11 #define EFX_MCDI_H
12 12
13 /** 13 /**
14 * enum efx_mcdi_state 14 * enum efx_mcdi_state
15 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the 15 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
16 * mcdi_lock then they are able to move to MCDI_STATE_RUNNING 16 * mcdi_lock then they are able to move to MCDI_STATE_RUNNING
17 * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that 17 * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that
18 * moved into this state is allowed to move out of it. 18 * moved into this state is allowed to move out of it.
19 * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread 19 * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
20 * has not yet consumed the result. For all other threads, equivalent to 20 * has not yet consumed the result. For all other threads, equivalent to
21 * MCDI_STATE_RUNNING. 21 * MCDI_STATE_RUNNING.
22 */ 22 */
23 enum efx_mcdi_state { 23 enum efx_mcdi_state {
24 MCDI_STATE_QUIESCENT, 24 MCDI_STATE_QUIESCENT,
25 MCDI_STATE_RUNNING, 25 MCDI_STATE_RUNNING,
26 MCDI_STATE_COMPLETED, 26 MCDI_STATE_COMPLETED,
27 }; 27 };
28 28
29 enum efx_mcdi_mode { 29 enum efx_mcdi_mode {
30 MCDI_MODE_POLL, 30 MCDI_MODE_POLL,
31 MCDI_MODE_EVENTS, 31 MCDI_MODE_EVENTS,
32 }; 32 };
33 33
34 /** 34 /**
35 * struct efx_mcdi_iface 35 * struct efx_mcdi_iface
36 * @state: Interface state. Waited for by mcdi_wq. 36 * @state: Interface state. Waited for by mcdi_wq.
37 * @wq: Wait queue for threads waiting for state != STATE_RUNNING 37 * @wq: Wait queue for threads waiting for state != STATE_RUNNING
38 * @iface_lock: Protects @credits, @seqno, @resprc, @resplen 38 * @iface_lock: Protects @credits, @seqno, @resprc, @resplen
39 * @mode: Poll for mcdi completion, or wait for an mcdi_event. 39 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
40 * Serialised by @lock 40 * Serialised by @lock
41 * @seqno: The next sequence number to use for mcdi requests. 41 * @seqno: The next sequence number to use for mcdi requests.
42 * Serialised by @lock 42 * Serialised by @lock
43 * @credits: Number of spurious MCDI completion events allowed before we 43 * @credits: Number of spurious MCDI completion events allowed before we
44 * trigger a fatal error. Protected by @lock 44 * trigger a fatal error. Protected by @lock
45 * @resprc: Returned MCDI completion 45 * @resprc: Returned MCDI completion
46 * @resplen: Returned payload length 46 * @resplen: Returned payload length
47 */ 47 */
48 struct efx_mcdi_iface { 48 struct efx_mcdi_iface {
49 atomic_t state; 49 atomic_t state;
50 wait_queue_head_t wq; 50 wait_queue_head_t wq;
51 spinlock_t iface_lock; 51 spinlock_t iface_lock;
52 enum efx_mcdi_mode mode; 52 enum efx_mcdi_mode mode;
53 unsigned int credits; 53 unsigned int credits;
54 unsigned int seqno; 54 unsigned int seqno;
55 unsigned int resprc; 55 unsigned int resprc;
56 size_t resplen; 56 size_t resplen;
57 }; 57 };
58 58
59 struct efx_mcdi_mon { 59 struct efx_mcdi_mon {
60 struct efx_buffer dma_buf; 60 struct efx_buffer dma_buf;
61 struct mutex update_lock; 61 struct mutex update_lock;
62 unsigned long last_update; 62 unsigned long last_update;
63 struct device *device; 63 struct device *device;
64 struct efx_mcdi_mon_attribute *attrs; 64 struct efx_mcdi_mon_attribute *attrs;
65 unsigned int n_attrs; 65 unsigned int n_attrs;
66 }; 66 };
67 67
68 extern void efx_mcdi_init(struct efx_nic *efx); 68 extern void efx_mcdi_init(struct efx_nic *efx);
69 69
70 extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const u8 *inbuf, 70 extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const u8 *inbuf,
71 size_t inlen, u8 *outbuf, size_t outlen, 71 size_t inlen, u8 *outbuf, size_t outlen,
72 size_t *outlen_actual); 72 size_t *outlen_actual);
73 73
74 extern void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, 74 extern void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
75 const u8 *inbuf, size_t inlen); 75 const u8 *inbuf, size_t inlen);
76 extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen, 76 extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
77 u8 *outbuf, size_t outlen, 77 u8 *outbuf, size_t outlen,
78 size_t *outlen_actual); 78 size_t *outlen_actual);
79 79
80 extern int efx_mcdi_poll_reboot(struct efx_nic *efx); 80 extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
81 extern void efx_mcdi_mode_poll(struct efx_nic *efx); 81 extern void efx_mcdi_mode_poll(struct efx_nic *efx);
82 extern void efx_mcdi_mode_event(struct efx_nic *efx); 82 extern void efx_mcdi_mode_event(struct efx_nic *efx);
83 83
84 extern void efx_mcdi_process_event(struct efx_channel *channel, 84 extern void efx_mcdi_process_event(struct efx_channel *channel,
85 efx_qword_t *event); 85 efx_qword_t *event);
86 extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); 86 extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
87 87
88 #define MCDI_PTR2(_buf, _ofst) \ 88 #define MCDI_PTR2(_buf, _ofst) \
89 (((u8 *)_buf) + _ofst) 89 (((u8 *)_buf) + _ofst)
90 #define MCDI_SET_DWORD2(_buf, _ofst, _value) \ 90 #define MCDI_SET_DWORD2(_buf, _ofst, _value) \
91 EFX_POPULATE_DWORD_1(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \ 91 EFX_POPULATE_DWORD_1(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \
92 EFX_DWORD_0, _value) 92 EFX_DWORD_0, _value)
93 #define MCDI_DWORD2(_buf, _ofst) \ 93 #define MCDI_DWORD2(_buf, _ofst) \
94 EFX_DWORD_FIELD(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \ 94 EFX_DWORD_FIELD(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)), \
95 EFX_DWORD_0) 95 EFX_DWORD_0)
96 #define MCDI_QWORD2(_buf, _ofst) \ 96 #define MCDI_QWORD2(_buf, _ofst) \
97 EFX_QWORD_FIELD64(*((efx_qword_t *)MCDI_PTR2(_buf, _ofst)), \ 97 EFX_QWORD_FIELD64(*((efx_qword_t *)MCDI_PTR2(_buf, _ofst)), \
98 EFX_QWORD_0) 98 EFX_QWORD_0)
99 99
100 #define MCDI_PTR(_buf, _ofst) \ 100 #define MCDI_PTR(_buf, _ofst) \
101 MCDI_PTR2(_buf, MC_CMD_ ## _ofst ## _OFST) 101 MCDI_PTR2(_buf, MC_CMD_ ## _ofst ## _OFST)
102 #define MCDI_ARRAY_PTR(_buf, _field, _type, _index) \ 102 #define MCDI_ARRAY_PTR(_buf, _field, _type, _index) \
103 MCDI_PTR2(_buf, \ 103 MCDI_PTR2(_buf, \
104 MC_CMD_ ## _field ## _OFST + \ 104 MC_CMD_ ## _field ## _OFST + \
105 (_index) * MC_CMD_ ## _type ## _TYPEDEF_LEN) 105 (_index) * MC_CMD_ ## _type ## _TYPEDEF_LEN)
106 #define MCDI_SET_DWORD(_buf, _ofst, _value) \ 106 #define MCDI_SET_DWORD(_buf, _ofst, _value) \
107 MCDI_SET_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST, _value) 107 MCDI_SET_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST, _value)
108 #define MCDI_DWORD(_buf, _ofst) \ 108 #define MCDI_DWORD(_buf, _ofst) \
109 MCDI_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST) 109 MCDI_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)
110 #define MCDI_QWORD(_buf, _ofst) \ 110 #define MCDI_QWORD(_buf, _ofst) \
111 MCDI_QWORD2(_buf, MC_CMD_ ## _ofst ## _OFST) 111 MCDI_QWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)
112 112
113 #define MCDI_EVENT_FIELD(_ev, _field) \ 113 #define MCDI_EVENT_FIELD(_ev, _field) \
114 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field) 114 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
115 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \ 115 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
116 EFX_DWORD_FIELD( \ 116 EFX_EXTRACT_DWORD( \
117 *((efx_dword_t *) \ 117 *((efx_dword_t *) \
118 (MCDI_ARRAY_PTR(_buf, _field1, _type, _index) + \ 118 (MCDI_ARRAY_PTR(_buf, _field1, _type, _index) + \
119 (MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _OFST & ~3))), \ 119 (MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _OFST & ~3))), \
120 MC_CMD_ ## _type ## _TYPEDEF_ ## _field2) 120 MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f, \
121 (MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f) + \
122 MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _WIDTH - 1)
121 123
122 extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len); 124 extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
123 extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating, 125 extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
124 bool *was_attached_out); 126 bool *was_attached_out);
125 extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address, 127 extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
126 u16 *fw_subtype_list, u32 *capabilities); 128 u16 *fw_subtype_list, u32 *capabilities);
127 extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, 129 extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
128 u32 dest_evq); 130 u32 dest_evq);
129 extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out); 131 extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
130 extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, 132 extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
131 size_t *size_out, size_t *erase_size_out, 133 size_t *size_out, size_t *erase_size_out,
132 bool *protected_out); 134 bool *protected_out);
133 extern int efx_mcdi_nvram_update_start(struct efx_nic *efx, 135 extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
134 unsigned int type); 136 unsigned int type);
135 extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type, 137 extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
136 loff_t offset, u8 *buffer, size_t length); 138 loff_t offset, u8 *buffer, size_t length);
137 extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type, 139 extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
138 loff_t offset, const u8 *buffer, 140 loff_t offset, const u8 *buffer,
139 size_t length); 141 size_t length);
140 #define EFX_MCDI_NVRAM_LEN_MAX 128 142 #define EFX_MCDI_NVRAM_LEN_MAX 128
141 extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type, 143 extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
142 loff_t offset, size_t length); 144 loff_t offset, size_t length);
143 extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx, 145 extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
144 unsigned int type); 146 unsigned int type);
145 extern int efx_mcdi_nvram_test_all(struct efx_nic *efx); 147 extern int efx_mcdi_nvram_test_all(struct efx_nic *efx);
146 extern int efx_mcdi_handle_assertion(struct efx_nic *efx); 148 extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
147 extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode); 149 extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
148 extern int efx_mcdi_reset_port(struct efx_nic *efx); 150 extern int efx_mcdi_reset_port(struct efx_nic *efx);
149 extern int efx_mcdi_reset_mc(struct efx_nic *efx); 151 extern int efx_mcdi_reset_mc(struct efx_nic *efx);
150 extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, 152 extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
151 const u8 *mac, int *id_out); 153 const u8 *mac, int *id_out);
152 extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out); 154 extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
153 extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id); 155 extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
154 extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx); 156 extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
155 extern int efx_mcdi_flush_rxqs(struct efx_nic *efx); 157 extern int efx_mcdi_flush_rxqs(struct efx_nic *efx);
156 extern int efx_mcdi_set_mac(struct efx_nic *efx); 158 extern int efx_mcdi_set_mac(struct efx_nic *efx);
157 extern int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr, 159 extern int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
158 u32 dma_len, int enable, int clear); 160 u32 dma_len, int enable, int clear);
159 extern int efx_mcdi_mac_reconfigure(struct efx_nic *efx); 161 extern int efx_mcdi_mac_reconfigure(struct efx_nic *efx);
160 extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx); 162 extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
161 163
162 #ifdef CONFIG_SFC_MCDI_MON 164 #ifdef CONFIG_SFC_MCDI_MON
163 extern int efx_mcdi_mon_probe(struct efx_nic *efx); 165 extern int efx_mcdi_mon_probe(struct efx_nic *efx);
164 extern void efx_mcdi_mon_remove(struct efx_nic *efx); 166 extern void efx_mcdi_mon_remove(struct efx_nic *efx);
165 #else 167 #else
166 static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; } 168 static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
167 static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {} 169 static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
168 #endif 170 #endif
169 171
170 #endif /* EFX_MCDI_H */ 172 #endif /* EFX_MCDI_H */
171 173