qed: Add PF max bandwidth configuration support
[deliverable/linux.git] / drivers / net / ethernet / qlogic / qed / qed_mcp.h
CommitLineData
fe56b9e6
YM
1/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#ifndef _QED_MCP_H
10#define _QED_MCP_H
11
12#include <linux/types.h>
13#include <linux/delay.h>
fe56b9e6 14#include <linux/slab.h>
5529bad9 15#include <linux/spinlock.h>
fe56b9e6
YM
16#include "qed_hsi.h"
17
cc875c2e
YM
18struct qed_mcp_link_speed_params {
19 bool autoneg;
20 u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
21 u32 forced_speed; /* In Mb/s */
22};
23
24struct qed_mcp_link_pause_params {
25 bool autoneg;
26 bool forced_rx;
27 bool forced_tx;
28};
29
30struct qed_mcp_link_params {
31 struct qed_mcp_link_speed_params speed;
32 struct qed_mcp_link_pause_params pause;
33 u32 loopback_mode;
34};
35
36struct qed_mcp_link_capabilities {
37 u32 speed_capabilities;
38};
39
40struct qed_mcp_link_state {
41 bool link_up;
42
4b01e519
MC
43 /* Actual link speed in Mb/s */
44 u32 line_speed;
45
46 /* PF max speed in Mb/s, deduced from line_speed
47 * according to PF max bandwidth configuration.
48 */
49 u32 speed;
cc875c2e
YM
50 bool full_duplex;
51
52 bool an;
53 bool an_complete;
54 bool parallel_detection;
55 bool pfc_enabled;
56
57#define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
58#define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
59#define QED_LINK_PARTNER_SPEED_10G BIT(2)
60#define QED_LINK_PARTNER_SPEED_20G BIT(3)
61#define QED_LINK_PARTNER_SPEED_40G BIT(4)
62#define QED_LINK_PARTNER_SPEED_50G BIT(5)
63#define QED_LINK_PARTNER_SPEED_100G BIT(6)
64 u32 partner_adv_speed;
65
66 bool partner_tx_flow_ctrl_en;
67 bool partner_rx_flow_ctrl_en;
68
69#define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
70#define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
71#define QED_LINK_PARTNER_BOTH_PAUSE (3)
72 u8 partner_adv_pause;
73
74 bool sfp_tx_fault;
75};
76
fe56b9e6
YM
77struct qed_mcp_function_info {
78 u8 pause_on_host;
79
80 enum qed_pci_personality protocol;
81
82 u8 bandwidth_min;
83 u8 bandwidth_max;
84
85 u8 mac[ETH_ALEN];
86
87 u64 wwn_port;
88 u64 wwn_node;
89
90#define QED_MCP_VLAN_UNSET (0xffff)
91 u16 ovlan;
92};
93
94struct qed_mcp_nvm_common {
95 u32 offset;
96 u32 param;
97 u32 resp;
98 u32 cmd;
99};
100
101struct qed_mcp_drv_version {
102 u32 version;
103 u8 name[MCP_DRV_VER_STR_SIZE - 4];
104};
105
cc875c2e
YM
106/**
107 * @brief - returns the link params of the hw function
108 *
109 * @param p_hwfn
110 *
111 * @returns pointer to link params
112 */
113struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
114
115/**
116 * @brief - return the link state of the hw function
117 *
118 * @param p_hwfn
119 *
120 * @returns pointer to link state
121 */
122struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
123
124/**
125 * @brief - return the link capabilities of the hw function
126 *
127 * @param p_hwfn
128 *
129 * @returns pointer to link capabilities
130 */
131struct qed_mcp_link_capabilities
132 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
133
134/**
135 * @brief Request the MFW to set the the link according to 'link_input'.
136 *
137 * @param p_hwfn
138 * @param p_ptt
139 * @param b_up - raise link if `true'. Reset link if `false'.
140 *
141 * @return int
142 */
143int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
144 struct qed_ptt *p_ptt,
145 bool b_up);
146
fe56b9e6
YM
147/**
148 * @brief Get the management firmware version value
149 *
150 * @param cdev - qed dev pointer
151 * @param mfw_ver - mfw version value
152 *
153 * @return int - 0 - operation was successul.
154 */
155int qed_mcp_get_mfw_ver(struct qed_dev *cdev,
156 u32 *mfw_ver);
157
cc875c2e
YM
158/**
159 * @brief Get media type value of the port.
160 *
161 * @param cdev - qed dev pointer
162 * @param mfw_ver - media type value
163 *
164 * @return int -
165 * 0 - Operation was successul.
166 * -EBUSY - Operation failed
167 */
168int qed_mcp_get_media_type(struct qed_dev *cdev,
169 u32 *media_type);
170
fe56b9e6
YM
171/**
172 * @brief General function for sending commands to the MCP
173 * mailbox. It acquire mutex lock for the entire
174 * operation, from sending the request until the MCP
175 * response. Waiting for MCP response will be checked up
176 * to 5 seconds every 5ms.
177 *
178 * @param p_hwfn - hw function
179 * @param p_ptt - PTT required for register access
180 * @param cmd - command to be sent to the MCP.
181 * @param param - Optional param
182 * @param o_mcp_resp - The MCP response code (exclude sequence).
183 * @param o_mcp_param- Optional parameter provided by the MCP
184 * response
185 * @return int - 0 - operation
186 * was successul.
187 */
188int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
189 struct qed_ptt *p_ptt,
190 u32 cmd,
191 u32 param,
192 u32 *o_mcp_resp,
193 u32 *o_mcp_param);
194
195/**
196 * @brief - drains the nig, allowing completion to pass in case of pauses.
197 * (Should be called only from sleepable context)
198 *
199 * @param p_hwfn
200 * @param p_ptt
201 */
202int qed_mcp_drain(struct qed_hwfn *p_hwfn,
203 struct qed_ptt *p_ptt);
204
cee4d264
MC
205/**
206 * @brief Get the flash size value
207 *
208 * @param p_hwfn
209 * @param p_ptt
210 * @param p_flash_size - flash size in bytes to be filled.
211 *
212 * @return int - 0 - operation was successul.
213 */
214int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
215 struct qed_ptt *p_ptt,
216 u32 *p_flash_size);
217
fe56b9e6
YM
218/**
219 * @brief Send driver version to MFW
220 *
221 * @param p_hwfn
222 * @param p_ptt
223 * @param version - Version value
224 * @param name - Protocol driver name
225 *
226 * @return int - 0 - operation was successul.
227 */
228int
229qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
230 struct qed_ptt *p_ptt,
231 struct qed_mcp_drv_version *p_ver);
232
91420b83
SK
233/**
234 * @brief Set LED status
235 *
236 * @param p_hwfn
237 * @param p_ptt
238 * @param mode - LED mode
239 *
240 * @return int - 0 - operation was successful.
241 */
242int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
243 struct qed_ptt *p_ptt,
244 enum qed_led_mode mode);
245
fe56b9e6
YM
246/* Using hwfn number (and not pf_num) is required since in CMT mode,
247 * same pf_num may be used by two different hwfn
248 * TODO - this shouldn't really be in .h file, but until all fields
249 * required during hw-init will be placed in their correct place in shmem
250 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
251 */
252#define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
253 ((rel_pfid) | \
254 ((p_hwfn)->abs_pf_id & 1) << 3) : \
255 rel_pfid)
256#define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
257
258/* TODO - this is only correct as long as only BB is supported, and
259 * no port-swapping is implemented; Afterwards we'll need to fix it.
260 */
261#define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
262 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
263struct qed_mcp_info {
5529bad9
TT
264 spinlock_t lock;
265 bool block_mb_sending;
fe56b9e6
YM
266 u32 public_base;
267 u32 drv_mb_addr;
268 u32 mfw_mb_addr;
269 u32 port_addr;
270 u16 drv_mb_seq;
271 u16 drv_pulse_seq;
cc875c2e
YM
272 struct qed_mcp_link_params link_input;
273 struct qed_mcp_link_state link_output;
274 struct qed_mcp_link_capabilities link_capabilities;
fe56b9e6 275 struct qed_mcp_function_info func_info;
fe56b9e6
YM
276 u8 *mfw_mb_cur;
277 u8 *mfw_mb_shadow;
278 u16 mfw_mb_length;
279 u16 mcp_hist;
280};
281
5529bad9
TT
282struct qed_mcp_mb_params {
283 u32 cmd;
284 u32 param;
285 union drv_union_data *p_data_src;
286 union drv_union_data *p_data_dst;
287 u32 mcp_resp;
288 u32 mcp_param;
289};
290
fe56b9e6
YM
291/**
292 * @brief Initialize the interface with the MCP
293 *
294 * @param p_hwfn - HW func
295 * @param p_ptt - PTT required for register access
296 *
297 * @return int
298 */
299int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
300 struct qed_ptt *p_ptt);
301
302/**
303 * @brief Initialize the port interface with the MCP
304 *
305 * @param p_hwfn
306 * @param p_ptt
307 * Can only be called after `num_ports_in_engines' is set
308 */
309void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
310 struct qed_ptt *p_ptt);
311/**
312 * @brief Releases resources allocated during the init process.
313 *
314 * @param p_hwfn - HW func
315 * @param p_ptt - PTT required for register access
316 *
317 * @return int
318 */
319
320int qed_mcp_free(struct qed_hwfn *p_hwfn);
321
cc875c2e
YM
322/**
323 * @brief This function is called from the DPC context. After
324 * pointing PTT to the mfw mb, check for events sent by the MCP
325 * to the driver and ack them. In case a critical event
326 * detected, it will be handled here, otherwise the work will be
327 * queued to a sleepable work-queue.
328 *
329 * @param p_hwfn - HW function
330 * @param p_ptt - PTT required for register access
331 * @return int - 0 - operation
332 * was successul.
333 */
334int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
335 struct qed_ptt *p_ptt);
336
fe56b9e6
YM
337/**
338 * @brief Sends a LOAD_REQ to the MFW, and in case operation
339 * succeed, returns whether this PF is the first on the
340 * chip/engine/port or function. This function should be
341 * called when driver is ready to accept MFW events after
342 * Storms initializations are done.
343 *
344 * @param p_hwfn - hw function
345 * @param p_ptt - PTT required for register access
346 * @param p_load_code - The MCP response param containing one
347 * of the following:
348 * FW_MSG_CODE_DRV_LOAD_ENGINE
349 * FW_MSG_CODE_DRV_LOAD_PORT
350 * FW_MSG_CODE_DRV_LOAD_FUNCTION
351 * @return int -
352 * 0 - Operation was successul.
353 * -EBUSY - Operation failed
354 */
355int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
356 struct qed_ptt *p_ptt,
357 u32 *p_load_code);
358
359/**
360 * @brief Read the MFW mailbox into Current buffer.
361 *
362 * @param p_hwfn
363 * @param p_ptt
364 */
365void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
366 struct qed_ptt *p_ptt);
367
368/**
369 * @brief - calls during init to read shmem of all function-related info.
370 *
371 * @param p_hwfn
372 *
373 * @param return 0 upon success.
374 */
375int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
376 struct qed_ptt *p_ptt);
377
378/**
379 * @brief - Reset the MCP using mailbox command.
380 *
381 * @param p_hwfn
382 * @param p_ptt
383 *
384 * @param return 0 upon success.
385 */
386int qed_mcp_reset(struct qed_hwfn *p_hwfn,
387 struct qed_ptt *p_ptt);
388
389/**
390 * @brief indicates whether the MFW objects [under mcp_info] are accessible
391 *
392 * @param p_hwfn
393 *
394 * @return true iff MFW is running and mcp_info is initialized
395 */
396bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
4b01e519
MC
397int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
398int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
399 struct qed_ptt *p_ptt,
400 struct qed_mcp_link_state *p_link,
401 u8 max_bw);
fe56b9e6 402#endif
This page took 0.101779 seconds and 5 git commands to generate.