2 * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
5 * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/pci.h>
38 #include "t4vf_common.h"
39 #include "t4vf_defs.h"
41 #include "../cxgb4/t4_regs.h"
42 #include "../cxgb4/t4fw_api.h"
45 * Wait for the device to become ready (signified by our "who am I" register
46 * returning a value other than all 1's). Return an error if it doesn't
49 int t4vf_wait_dev_ready(struct adapter *adapter)
51 const u32 whoami = T4VF_PL_BASE_ADDR + PL_VF_WHOAMI;
52 const u32 notready1 = 0xffffffff;
53 const u32 notready2 = 0xeeeeeeee;
56 val = t4_read_reg(adapter, whoami);
57 if (val != notready1 && val != notready2)
60 val = t4_read_reg(adapter, whoami);
61 if (val != notready1 && val != notready2)
68 * Get the reply to a mailbox command and store it in @rpl in big-endian order
69 * (since the firmware data structures are specified in a big-endian layout).
71 static void get_mbox_rpl(struct adapter *adapter, __be64 *rpl, int size,
74 for ( ; size; size -= 8, mbox_data += 8)
75 *rpl++ = cpu_to_be64(t4_read_reg64(adapter, mbox_data));
79 * Dump contents of mailbox with a leading tag.
81 static void dump_mbox(struct adapter *adapter, const char *tag, u32 mbox_data)
83 dev_err(adapter->pdev_dev,
84 "mbox %s: %llx %llx %llx %llx %llx %llx %llx %llx\n", tag,
85 (unsigned long long)t4_read_reg64(adapter, mbox_data + 0),
86 (unsigned long long)t4_read_reg64(adapter, mbox_data + 8),
87 (unsigned long long)t4_read_reg64(adapter, mbox_data + 16),
88 (unsigned long long)t4_read_reg64(adapter, mbox_data + 24),
89 (unsigned long long)t4_read_reg64(adapter, mbox_data + 32),
90 (unsigned long long)t4_read_reg64(adapter, mbox_data + 40),
91 (unsigned long long)t4_read_reg64(adapter, mbox_data + 48),
92 (unsigned long long)t4_read_reg64(adapter, mbox_data + 56));
96 * t4vf_wr_mbox_core - send a command to FW through the mailbox
97 * @adapter: the adapter
98 * @cmd: the command to write
99 * @size: command length in bytes
100 * @rpl: where to optionally store the reply
101 * @sleep_ok: if true we may sleep while awaiting command completion
103 * Sends the given command to FW through the mailbox and waits for the
104 * FW to execute the command. If @rpl is not %NULL it is used to store
105 * the FW's reply to the command. The command and its optional reply
106 * are of the same length. FW can take up to 500 ms to respond.
107 * @sleep_ok determines whether we may sleep while awaiting the response.
108 * If sleeping is allowed we use progressive backoff otherwise we spin.
110 * The return value is 0 on success or a negative errno on failure. A
111 * failure can happen either because we are not able to execute the
112 * command or FW executes it but signals an error. In the latter case
113 * the return value is the error code indicated by FW (negated).
115 int t4vf_wr_mbox_core(struct adapter *adapter, const void *cmd, int size,
116 void *rpl, bool sleep_ok)
118 static const int delay[] = {
119 1, 1, 3, 5, 10, 10, 20, 50, 100
123 int i, ms, delay_idx;
125 u32 mbox_data = T4VF_MBDATA_BASE_ADDR;
126 u32 mbox_ctl = T4VF_CIM_BASE_ADDR + CIM_VF_EXT_MAILBOX_CTRL;
129 * Commands must be multiples of 16 bytes in length and may not be
130 * larger than the size of the Mailbox Data register array.
132 if ((size % 16) != 0 ||
133 size > NUM_CIM_VF_MAILBOX_DATA_INSTANCES * 4)
137 * Loop trying to get ownership of the mailbox. Return an error
138 * if we can't gain ownership.
140 v = MBOWNER_GET(t4_read_reg(adapter, mbox_ctl));
141 for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
142 v = MBOWNER_GET(t4_read_reg(adapter, mbox_ctl));
143 if (v != MBOX_OWNER_DRV)
144 return v == MBOX_OWNER_FW ? -EBUSY : -ETIMEDOUT;
147 * Write the command array into the Mailbox Data register array and
148 * transfer ownership of the mailbox to the firmware.
150 * For the VFs, the Mailbox Data "registers" are actually backed by
151 * T4's "MA" interface rather than PL Registers (as is the case for
152 * the PFs). Because these are in different coherency domains, the
153 * write to the VF's PL-register-backed Mailbox Control can race in
154 * front of the writes to the MA-backed VF Mailbox Data "registers".
155 * So we need to do a read-back on at least one byte of the VF Mailbox
156 * Data registers before doing the write to the VF Mailbox Control
159 for (i = 0, p = cmd; i < size; i += 8)
160 t4_write_reg64(adapter, mbox_data + i, be64_to_cpu(*p++));
161 t4_read_reg(adapter, mbox_data); /* flush write */
163 t4_write_reg(adapter, mbox_ctl,
164 MBMSGVALID | MBOWNER(MBOX_OWNER_FW));
165 t4_read_reg(adapter, mbox_ctl); /* flush write */
168 * Spin waiting for firmware to acknowledge processing our command.
173 for (i = 0; i < FW_CMD_MAX_TIMEOUT; i += ms) {
175 ms = delay[delay_idx];
176 if (delay_idx < ARRAY_SIZE(delay) - 1)
183 * If we're the owner, see if this is the reply we wanted.
185 v = t4_read_reg(adapter, mbox_ctl);
186 if (MBOWNER_GET(v) == MBOX_OWNER_DRV) {
188 * If the Message Valid bit isn't on, revoke ownership
189 * of the mailbox and continue waiting for our reply.
191 if ((v & MBMSGVALID) == 0) {
192 t4_write_reg(adapter, mbox_ctl,
193 MBOWNER(MBOX_OWNER_NONE));
198 * We now have our reply. Extract the command return
199 * value, copy the reply back to our caller's buffer
200 * (if specified) and revoke ownership of the mailbox.
201 * We return the (negated) firmware command return
202 * code (this depends on FW_SUCCESS == 0).
205 /* return value in low-order little-endian word */
206 v = t4_read_reg(adapter, mbox_data);
207 if (FW_CMD_RETVAL_GET(v))
208 dump_mbox(adapter, "FW Error", mbox_data);
211 /* request bit in high-order BE word */
212 WARN_ON((be32_to_cpu(*(const u32 *)cmd)
213 & FW_CMD_REQUEST) == 0);
214 get_mbox_rpl(adapter, rpl, size, mbox_data);
215 WARN_ON((be32_to_cpu(*(u32 *)rpl)
216 & FW_CMD_REQUEST) != 0);
218 t4_write_reg(adapter, mbox_ctl,
219 MBOWNER(MBOX_OWNER_NONE));
220 return -FW_CMD_RETVAL_GET(v);
225 * We timed out. Return the error ...
227 dump_mbox(adapter, "FW Timeout", mbox_data);
232 * hash_mac_addr - return the hash value of a MAC address
233 * @addr: the 48-bit Ethernet MAC address
235 * Hashes a MAC address according to the hash function used by hardware
236 * inexact (hash) address matching.
238 static int hash_mac_addr(const u8 *addr)
240 u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
241 u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
249 * init_link_config - initialize a link's SW state
250 * @lc: structure holding the link state
251 * @caps: link capabilities
253 * Initializes the SW state maintained for each link, including the link's
254 * capabilities and default speed/flow-control/autonegotiation settings.
256 static void init_link_config(struct link_config *lc, unsigned int caps)
258 lc->supported = caps;
259 lc->requested_speed = 0;
261 lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
262 if (lc->supported & SUPPORTED_Autoneg) {
263 lc->advertising = lc->supported;
264 lc->autoneg = AUTONEG_ENABLE;
265 lc->requested_fc |= PAUSE_AUTONEG;
268 lc->autoneg = AUTONEG_DISABLE;
273 * t4vf_port_init - initialize port hardware/software state
274 * @adapter: the adapter
275 * @pidx: the adapter port index
277 int t4vf_port_init(struct adapter *adapter, int pidx)
279 struct port_info *pi = adap2pinfo(adapter, pidx);
280 struct fw_vi_cmd vi_cmd, vi_rpl;
281 struct fw_port_cmd port_cmd, port_rpl;
286 * Execute a VI Read command to get our Virtual Interface information
287 * like MAC address, etc.
289 memset(&vi_cmd, 0, sizeof(vi_cmd));
290 vi_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
293 vi_cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(vi_cmd));
294 vi_cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID(pi->viid));
295 v = t4vf_wr_mbox(adapter, &vi_cmd, sizeof(vi_cmd), &vi_rpl);
299 BUG_ON(pi->port_id != FW_VI_CMD_PORTID_GET(vi_rpl.portid_pkd));
300 pi->rss_size = FW_VI_CMD_RSSSIZE_GET(be16_to_cpu(vi_rpl.rsssize_pkd));
301 t4_os_set_hw_addr(adapter, pidx, vi_rpl.mac);
304 * If we don't have read access to our port information, we're done
305 * now. Otherwise, execute a PORT Read command to get it ...
307 if (!(adapter->params.vfres.r_caps & FW_CMD_CAP_PORT))
310 memset(&port_cmd, 0, sizeof(port_cmd));
311 port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP(FW_PORT_CMD) |
314 FW_PORT_CMD_PORTID(pi->port_id));
315 port_cmd.action_to_len16 =
316 cpu_to_be32(FW_PORT_CMD_ACTION(FW_PORT_ACTION_GET_PORT_INFO) |
318 v = t4vf_wr_mbox(adapter, &port_cmd, sizeof(port_cmd), &port_rpl);
323 word = be16_to_cpu(port_rpl.u.info.pcap);
324 if (word & FW_PORT_CAP_SPEED_100M)
325 v |= SUPPORTED_100baseT_Full;
326 if (word & FW_PORT_CAP_SPEED_1G)
327 v |= SUPPORTED_1000baseT_Full;
328 if (word & FW_PORT_CAP_SPEED_10G)
329 v |= SUPPORTED_10000baseT_Full;
330 if (word & FW_PORT_CAP_ANEG)
331 v |= SUPPORTED_Autoneg;
332 init_link_config(&pi->link_cfg, v);
338 * t4vf_fw_reset - issue a reset to FW
339 * @adapter: the adapter
341 * Issues a reset command to FW. For a Physical Function this would
342 * result in the Firmware reseting all of its state. For a Virtual
343 * Function this just resets the state associated with the VF.
345 int t4vf_fw_reset(struct adapter *adapter)
347 struct fw_reset_cmd cmd;
349 memset(&cmd, 0, sizeof(cmd));
350 cmd.op_to_write = cpu_to_be32(FW_CMD_OP(FW_RESET_CMD) |
352 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
353 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
357 * t4vf_query_params - query FW or device parameters
358 * @adapter: the adapter
359 * @nparams: the number of parameters
360 * @params: the parameter names
361 * @vals: the parameter values
363 * Reads the values of firmware or device parameters. Up to 7 parameters
364 * can be queried at once.
366 int t4vf_query_params(struct adapter *adapter, unsigned int nparams,
367 const u32 *params, u32 *vals)
370 struct fw_params_cmd cmd, rpl;
371 struct fw_params_param *p;
377 memset(&cmd, 0, sizeof(cmd));
378 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PARAMS_CMD) |
381 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
382 param[nparams].mnem), 16);
383 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
384 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++)
385 p->mnem = htonl(*params++);
387 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
389 for (i = 0, p = &rpl.param[0]; i < nparams; i++, p++)
390 *vals++ = be32_to_cpu(p->val);
395 * t4vf_set_params - sets FW or device parameters
396 * @adapter: the adapter
397 * @nparams: the number of parameters
398 * @params: the parameter names
399 * @vals: the parameter values
401 * Sets the values of firmware or device parameters. Up to 7 parameters
402 * can be specified at once.
404 int t4vf_set_params(struct adapter *adapter, unsigned int nparams,
405 const u32 *params, const u32 *vals)
408 struct fw_params_cmd cmd;
409 struct fw_params_param *p;
415 memset(&cmd, 0, sizeof(cmd));
416 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PARAMS_CMD) |
419 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
420 param[nparams]), 16);
421 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
422 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++) {
423 p->mnem = cpu_to_be32(*params++);
424 p->val = cpu_to_be32(*vals++);
427 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
431 * t4vf_get_sge_params - retrieve adapter Scatter gather Engine parameters
432 * @adapter: the adapter
434 * Retrieves various core SGE parameters in the form of hardware SGE
435 * register values. The caller is responsible for decoding these as
436 * needed. The SGE parameters are stored in @adapter->params.sge.
438 int t4vf_get_sge_params(struct adapter *adapter)
440 struct sge_params *sge_params = &adapter->params.sge;
441 u32 params[7], vals[7];
444 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
445 FW_PARAMS_PARAM_XYZ(SGE_CONTROL));
446 params[1] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
447 FW_PARAMS_PARAM_XYZ(SGE_HOST_PAGE_SIZE));
448 params[2] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
449 FW_PARAMS_PARAM_XYZ(SGE_FL_BUFFER_SIZE0));
450 params[3] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
451 FW_PARAMS_PARAM_XYZ(SGE_FL_BUFFER_SIZE1));
452 params[4] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
453 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_0_AND_1));
454 params[5] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
455 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_2_AND_3));
456 params[6] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
457 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_4_AND_5));
458 v = t4vf_query_params(adapter, 7, params, vals);
461 sge_params->sge_control = vals[0];
462 sge_params->sge_host_page_size = vals[1];
463 sge_params->sge_fl_buffer_size[0] = vals[2];
464 sge_params->sge_fl_buffer_size[1] = vals[3];
465 sge_params->sge_timer_value_0_and_1 = vals[4];
466 sge_params->sge_timer_value_2_and_3 = vals[5];
467 sge_params->sge_timer_value_4_and_5 = vals[6];
469 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
470 FW_PARAMS_PARAM_XYZ(SGE_INGRESS_RX_THRESHOLD));
471 v = t4vf_query_params(adapter, 1, params, vals);
474 sge_params->sge_ingress_rx_threshold = vals[0];
480 * t4vf_get_vpd_params - retrieve device VPD paremeters
481 * @adapter: the adapter
483 * Retrives various device Vital Product Data parameters. The parameters
484 * are stored in @adapter->params.vpd.
486 int t4vf_get_vpd_params(struct adapter *adapter)
488 struct vpd_params *vpd_params = &adapter->params.vpd;
489 u32 params[7], vals[7];
492 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
493 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_CCLK));
494 v = t4vf_query_params(adapter, 1, params, vals);
497 vpd_params->cclk = vals[0];
503 * t4vf_get_dev_params - retrieve device paremeters
504 * @adapter: the adapter
506 * Retrives various device parameters. The parameters are stored in
507 * @adapter->params.dev.
509 int t4vf_get_dev_params(struct adapter *adapter)
511 struct dev_params *dev_params = &adapter->params.dev;
512 u32 params[7], vals[7];
515 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
516 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FWREV));
517 params[1] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
518 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_TPREV));
519 v = t4vf_query_params(adapter, 2, params, vals);
522 dev_params->fwrev = vals[0];
523 dev_params->tprev = vals[1];
529 * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration
530 * @adapter: the adapter
532 * Retrieves global RSS mode and parameters with which we have to live
533 * and stores them in the @adapter's RSS parameters.
535 int t4vf_get_rss_glb_config(struct adapter *adapter)
537 struct rss_params *rss = &adapter->params.rss;
538 struct fw_rss_glb_config_cmd cmd, rpl;
542 * Execute an RSS Global Configuration read command to retrieve
543 * our RSS configuration.
545 memset(&cmd, 0, sizeof(cmd));
546 cmd.op_to_write = cpu_to_be32(FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
549 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
550 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
555 * Transate the big-endian RSS Global Configuration into our
556 * cpu-endian format based on the RSS mode. We also do first level
557 * filtering at this point to weed out modes which don't support
560 rss->mode = FW_RSS_GLB_CONFIG_CMD_MODE_GET(
561 be32_to_cpu(rpl.u.manual.mode_pkd));
563 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
564 u32 word = be32_to_cpu(
565 rpl.u.basicvirtual.synmapen_to_hashtoeplitz);
567 rss->u.basicvirtual.synmapen =
568 ((word & FW_RSS_GLB_CONFIG_CMD_SYNMAPEN) != 0);
569 rss->u.basicvirtual.syn4tupenipv6 =
570 ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV6) != 0);
571 rss->u.basicvirtual.syn2tupenipv6 =
572 ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV6) != 0);
573 rss->u.basicvirtual.syn4tupenipv4 =
574 ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV4) != 0);
575 rss->u.basicvirtual.syn2tupenipv4 =
576 ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV4) != 0);
578 rss->u.basicvirtual.ofdmapen =
579 ((word & FW_RSS_GLB_CONFIG_CMD_OFDMAPEN) != 0);
581 rss->u.basicvirtual.tnlmapen =
582 ((word & FW_RSS_GLB_CONFIG_CMD_TNLMAPEN) != 0);
583 rss->u.basicvirtual.tnlalllookup =
584 ((word & FW_RSS_GLB_CONFIG_CMD_TNLALLLKP) != 0);
586 rss->u.basicvirtual.hashtoeplitz =
587 ((word & FW_RSS_GLB_CONFIG_CMD_HASHTOEPLITZ) != 0);
589 /* we need at least Tunnel Map Enable to be set */
590 if (!rss->u.basicvirtual.tnlmapen)
596 /* all unknown/unsupported RSS modes result in an error */
604 * t4vf_get_vfres - retrieve VF resource limits
605 * @adapter: the adapter
607 * Retrieves configured resource limits and capabilities for a virtual
608 * function. The results are stored in @adapter->vfres.
610 int t4vf_get_vfres(struct adapter *adapter)
612 struct vf_resources *vfres = &adapter->params.vfres;
613 struct fw_pfvf_cmd cmd, rpl;
618 * Execute PFVF Read command to get VF resource limits; bail out early
619 * with error on command failure.
621 memset(&cmd, 0, sizeof(cmd));
622 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PFVF_CMD) |
625 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
626 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
631 * Extract VF resource limits and return success.
633 word = be32_to_cpu(rpl.niqflint_niq);
634 vfres->niqflint = FW_PFVF_CMD_NIQFLINT_GET(word);
635 vfres->niq = FW_PFVF_CMD_NIQ_GET(word);
637 word = be32_to_cpu(rpl.type_to_neq);
638 vfres->neq = FW_PFVF_CMD_NEQ_GET(word);
639 vfres->pmask = FW_PFVF_CMD_PMASK_GET(word);
641 word = be32_to_cpu(rpl.tc_to_nexactf);
642 vfres->tc = FW_PFVF_CMD_TC_GET(word);
643 vfres->nvi = FW_PFVF_CMD_NVI_GET(word);
644 vfres->nexactf = FW_PFVF_CMD_NEXACTF_GET(word);
646 word = be32_to_cpu(rpl.r_caps_to_nethctrl);
647 vfres->r_caps = FW_PFVF_CMD_R_CAPS_GET(word);
648 vfres->wx_caps = FW_PFVF_CMD_WX_CAPS_GET(word);
649 vfres->nethctrl = FW_PFVF_CMD_NETHCTRL_GET(word);
655 * t4vf_read_rss_vi_config - read a VI's RSS configuration
656 * @adapter: the adapter
657 * @viid: Virtual Interface ID
658 * @config: pointer to host-native VI RSS Configuration buffer
660 * Reads the Virtual Interface's RSS configuration information and
661 * translates it into CPU-native format.
663 int t4vf_read_rss_vi_config(struct adapter *adapter, unsigned int viid,
664 union rss_vi_config *config)
666 struct fw_rss_vi_config_cmd cmd, rpl;
669 memset(&cmd, 0, sizeof(cmd));
670 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
673 FW_RSS_VI_CONFIG_CMD_VIID(viid));
674 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
675 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
679 switch (adapter->params.rss.mode) {
680 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
681 u32 word = be32_to_cpu(rpl.u.basicvirtual.defaultq_to_udpen);
683 config->basicvirtual.ip6fourtupen =
684 ((word & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN) != 0);
685 config->basicvirtual.ip6twotupen =
686 ((word & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN) != 0);
687 config->basicvirtual.ip4fourtupen =
688 ((word & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN) != 0);
689 config->basicvirtual.ip4twotupen =
690 ((word & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN) != 0);
691 config->basicvirtual.udpen =
692 ((word & FW_RSS_VI_CONFIG_CMD_UDPEN) != 0);
693 config->basicvirtual.defaultq =
694 FW_RSS_VI_CONFIG_CMD_DEFAULTQ_GET(word);
706 * t4vf_write_rss_vi_config - write a VI's RSS configuration
707 * @adapter: the adapter
708 * @viid: Virtual Interface ID
709 * @config: pointer to host-native VI RSS Configuration buffer
711 * Write the Virtual Interface's RSS configuration information
712 * (translating it into firmware-native format before writing).
714 int t4vf_write_rss_vi_config(struct adapter *adapter, unsigned int viid,
715 union rss_vi_config *config)
717 struct fw_rss_vi_config_cmd cmd, rpl;
719 memset(&cmd, 0, sizeof(cmd));
720 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
723 FW_RSS_VI_CONFIG_CMD_VIID(viid));
724 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
725 switch (adapter->params.rss.mode) {
726 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
729 if (config->basicvirtual.ip6fourtupen)
730 word |= FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
731 if (config->basicvirtual.ip6twotupen)
732 word |= FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
733 if (config->basicvirtual.ip4fourtupen)
734 word |= FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
735 if (config->basicvirtual.ip4twotupen)
736 word |= FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
737 if (config->basicvirtual.udpen)
738 word |= FW_RSS_VI_CONFIG_CMD_UDPEN;
739 word |= FW_RSS_VI_CONFIG_CMD_DEFAULTQ(
740 config->basicvirtual.defaultq);
741 cmd.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(word);
749 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
753 * t4vf_config_rss_range - configure a portion of the RSS mapping table
754 * @adapter: the adapter
755 * @viid: Virtual Interface of RSS Table Slice
756 * @start: starting entry in the table to write
757 * @n: how many table entries to write
758 * @rspq: values for the "Response Queue" (Ingress Queue) lookup table
759 * @nrspq: number of values in @rspq
761 * Programs the selected part of the VI's RSS mapping table with the
762 * provided values. If @nrspq < @n the supplied values are used repeatedly
763 * until the full table range is populated.
765 * The caller must ensure the values in @rspq are in the range 0..1023.
767 int t4vf_config_rss_range(struct adapter *adapter, unsigned int viid,
768 int start, int n, const u16 *rspq, int nrspq)
770 const u16 *rsp = rspq;
771 const u16 *rsp_end = rspq+nrspq;
772 struct fw_rss_ind_tbl_cmd cmd;
775 * Initialize firmware command template to write the RSS table.
777 memset(&cmd, 0, sizeof(cmd));
778 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_IND_TBL_CMD) |
781 FW_RSS_IND_TBL_CMD_VIID(viid));
782 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
785 * Each firmware RSS command can accommodate up to 32 RSS Ingress
786 * Queue Identifiers. These Ingress Queue IDs are packed three to
787 * a 32-bit word as 10-bit values with the upper remaining 2 bits
791 __be32 *qp = &cmd.iq0_to_iq2;
796 * Set up the firmware RSS command header to send the next
797 * "nq" Ingress Queue IDs to the firmware.
799 cmd.niqid = cpu_to_be16(nq);
800 cmd.startidx = cpu_to_be16(start);
803 * "nq" more done for the start of the next loop.
809 * While there are still Ingress Queue IDs to stuff into the
810 * current firmware RSS command, retrieve them from the
811 * Ingress Queue ID array and insert them into the command.
815 * Grab up to the next 3 Ingress Queue IDs (wrapping
816 * around the Ingress Queue ID array if necessary) and
817 * insert them into the firmware RSS command at the
818 * current 3-tuple position within the commad.
822 int nqbuf = min(3, nq);
825 qbuf[0] = qbuf[1] = qbuf[2] = 0;
832 *qp++ = cpu_to_be32(FW_RSS_IND_TBL_CMD_IQ0(qbuf[0]) |
833 FW_RSS_IND_TBL_CMD_IQ1(qbuf[1]) |
834 FW_RSS_IND_TBL_CMD_IQ2(qbuf[2]));
838 * Send this portion of the RRS table update to the firmware;
839 * bail out on any errors.
841 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
849 * t4vf_alloc_vi - allocate a virtual interface on a port
850 * @adapter: the adapter
851 * @port_id: physical port associated with the VI
853 * Allocate a new Virtual Interface and bind it to the indicated
854 * physical port. Return the new Virtual Interface Identifier on
855 * success, or a [negative] error number on failure.
857 int t4vf_alloc_vi(struct adapter *adapter, int port_id)
859 struct fw_vi_cmd cmd, rpl;
863 * Execute a VI command to allocate Virtual Interface and return its
866 memset(&cmd, 0, sizeof(cmd));
867 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
871 cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
873 cmd.portid_pkd = FW_VI_CMD_PORTID(port_id);
874 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
878 return FW_VI_CMD_VIID_GET(be16_to_cpu(rpl.type_viid));
882 * t4vf_free_vi -- free a virtual interface
883 * @adapter: the adapter
884 * @viid: the virtual interface identifier
886 * Free a previously allocated Virtual Interface. Return an error on
889 int t4vf_free_vi(struct adapter *adapter, int viid)
891 struct fw_vi_cmd cmd;
894 * Execute a VI command to free the Virtual Interface.
896 memset(&cmd, 0, sizeof(cmd));
897 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
900 cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
902 cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID(viid));
903 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
907 * t4vf_enable_vi - enable/disable a virtual interface
908 * @adapter: the adapter
909 * @viid: the Virtual Interface ID
910 * @rx_en: 1=enable Rx, 0=disable Rx
911 * @tx_en: 1=enable Tx, 0=disable Tx
913 * Enables/disables a virtual interface.
915 int t4vf_enable_vi(struct adapter *adapter, unsigned int viid,
916 bool rx_en, bool tx_en)
918 struct fw_vi_enable_cmd cmd;
920 memset(&cmd, 0, sizeof(cmd));
921 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_ENABLE_CMD) |
924 FW_VI_ENABLE_CMD_VIID(viid));
925 cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN(rx_en) |
926 FW_VI_ENABLE_CMD_EEN(tx_en) |
928 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
932 * t4vf_identify_port - identify a VI's port by blinking its LED
933 * @adapter: the adapter
934 * @viid: the Virtual Interface ID
935 * @nblinks: how many times to blink LED at 2.5 Hz
937 * Identifies a VI's port by blinking its LED.
939 int t4vf_identify_port(struct adapter *adapter, unsigned int viid,
940 unsigned int nblinks)
942 struct fw_vi_enable_cmd cmd;
944 memset(&cmd, 0, sizeof(cmd));
945 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_ENABLE_CMD) |
948 FW_VI_ENABLE_CMD_VIID(viid));
949 cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED |
951 cmd.blinkdur = cpu_to_be16(nblinks);
952 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
956 * t4vf_set_rxmode - set Rx properties of a virtual interface
957 * @adapter: the adapter
959 * @mtu: the new MTU or -1 for no change
960 * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
961 * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
962 * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
963 * @vlanex: 1 to enable hardware VLAN Tag extraction, 0 to disable it,
966 * Sets Rx properties of a virtual interface.
968 int t4vf_set_rxmode(struct adapter *adapter, unsigned int viid,
969 int mtu, int promisc, int all_multi, int bcast, int vlanex,
972 struct fw_vi_rxmode_cmd cmd;
974 /* convert to FW values */
976 mtu = FW_VI_RXMODE_CMD_MTU_MASK;
978 promisc = FW_VI_RXMODE_CMD_PROMISCEN_MASK;
980 all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_MASK;
982 bcast = FW_VI_RXMODE_CMD_BROADCASTEN_MASK;
984 vlanex = FW_VI_RXMODE_CMD_VLANEXEN_MASK;
986 memset(&cmd, 0, sizeof(cmd));
987 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_RXMODE_CMD) |
990 FW_VI_RXMODE_CMD_VIID(viid));
991 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
992 cmd.mtu_to_vlanexen =
993 cpu_to_be32(FW_VI_RXMODE_CMD_MTU(mtu) |
994 FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
995 FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
996 FW_VI_RXMODE_CMD_BROADCASTEN(bcast) |
997 FW_VI_RXMODE_CMD_VLANEXEN(vlanex));
998 return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
1002 * t4vf_alloc_mac_filt - allocates exact-match filters for MAC addresses
1003 * @adapter: the adapter
1004 * @viid: the Virtual Interface Identifier
1005 * @free: if true any existing filters for this VI id are first removed
1006 * @naddr: the number of MAC addresses to allocate filters for (up to 7)
1007 * @addr: the MAC address(es)
1008 * @idx: where to store the index of each allocated filter
1009 * @hash: pointer to hash address filter bitmap
1010 * @sleep_ok: call is allowed to sleep
1012 * Allocates an exact-match filter for each of the supplied addresses and
1013 * sets it to the corresponding address. If @idx is not %NULL it should
1014 * have at least @naddr entries, each of which will be set to the index of
1015 * the filter allocated for the corresponding MAC address. If a filter
1016 * could not be allocated for an address its index is set to 0xffff.
1017 * If @hash is not %NULL addresses that fail to allocate an exact filter
1018 * are hashed and update the hash filter bitmap pointed at by @hash.
1020 * Returns a negative error number or the number of filters allocated.
1022 int t4vf_alloc_mac_filt(struct adapter *adapter, unsigned int viid, bool free,
1023 unsigned int naddr, const u8 **addr, u16 *idx,
1024 u64 *hash, bool sleep_ok)
1026 int offset, ret = 0;
1027 unsigned nfilters = 0;
1028 unsigned int rem = naddr;
1029 struct fw_vi_mac_cmd cmd, rpl;
1030 unsigned int max_naddr = is_t4(adapter->chip) ?
1031 NUM_MPS_CLS_SRAM_L_INSTANCES :
1032 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1034 if (naddr > max_naddr)
1037 for (offset = 0; offset < naddr; /**/) {
1038 unsigned int fw_naddr = (rem < ARRAY_SIZE(cmd.u.exact)
1040 : ARRAY_SIZE(cmd.u.exact));
1041 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1042 u.exact[fw_naddr]), 16);
1043 struct fw_vi_mac_exact *p;
1046 memset(&cmd, 0, sizeof(cmd));
1047 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1050 (free ? FW_CMD_EXEC : 0) |
1051 FW_VI_MAC_CMD_VIID(viid));
1052 cmd.freemacs_to_len16 =
1053 cpu_to_be32(FW_VI_MAC_CMD_FREEMACS(free) |
1054 FW_CMD_LEN16(len16));
1056 for (i = 0, p = cmd.u.exact; i < fw_naddr; i++, p++) {
1057 p->valid_to_idx = cpu_to_be16(
1058 FW_VI_MAC_CMD_VALID |
1059 FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
1060 memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
1064 ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &rpl,
1066 if (ret && ret != -ENOMEM)
1069 for (i = 0, p = rpl.u.exact; i < fw_naddr; i++, p++) {
1070 u16 index = FW_VI_MAC_CMD_IDX_GET(
1071 be16_to_cpu(p->valid_to_idx));
1078 if (index < max_naddr)
1081 *hash |= (1ULL << hash_mac_addr(addr[offset+i]));
1090 * If there were no errors or we merely ran out of room in our MAC
1091 * address arena, return the number of filters actually written.
1093 if (ret == 0 || ret == -ENOMEM)
1099 * t4vf_change_mac - modifies the exact-match filter for a MAC address
1100 * @adapter: the adapter
1101 * @viid: the Virtual Interface ID
1102 * @idx: index of existing filter for old value of MAC address, or -1
1103 * @addr: the new MAC address value
1104 * @persist: if idx < 0, the new MAC allocation should be persistent
1106 * Modifies an exact-match filter and sets it to the new MAC address.
1107 * Note that in general it is not possible to modify the value of a given
1108 * filter so the generic way to modify an address filter is to free the
1109 * one being used by the old address value and allocate a new filter for
1110 * the new address value. @idx can be -1 if the address is a new
1113 * Returns a negative error number or the index of the filter with the new
1116 int t4vf_change_mac(struct adapter *adapter, unsigned int viid,
1117 int idx, const u8 *addr, bool persist)
1120 struct fw_vi_mac_cmd cmd, rpl;
1121 struct fw_vi_mac_exact *p = &cmd.u.exact[0];
1122 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1124 unsigned int max_naddr = is_t4(adapter->chip) ?
1125 NUM_MPS_CLS_SRAM_L_INSTANCES :
1126 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1129 * If this is a new allocation, determine whether it should be
1130 * persistent (across a "freemacs" operation) or not.
1133 idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
1135 memset(&cmd, 0, sizeof(cmd));
1136 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1139 FW_VI_MAC_CMD_VIID(viid));
1140 cmd.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
1141 p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID |
1142 FW_VI_MAC_CMD_IDX(idx));
1143 memcpy(p->macaddr, addr, sizeof(p->macaddr));
1145 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
1147 p = &rpl.u.exact[0];
1148 ret = FW_VI_MAC_CMD_IDX_GET(be16_to_cpu(p->valid_to_idx));
1149 if (ret >= max_naddr)
1156 * t4vf_set_addr_hash - program the MAC inexact-match hash filter
1157 * @adapter: the adapter
1158 * @viid: the Virtual Interface Identifier
1159 * @ucast: whether the hash filter should also match unicast addresses
1160 * @vec: the value to be written to the hash filter
1161 * @sleep_ok: call is allowed to sleep
1163 * Sets the 64-bit inexact-match hash filter for a virtual interface.
1165 int t4vf_set_addr_hash(struct adapter *adapter, unsigned int viid,
1166 bool ucast, u64 vec, bool sleep_ok)
1168 struct fw_vi_mac_cmd cmd;
1169 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1172 memset(&cmd, 0, sizeof(cmd));
1173 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1176 FW_VI_ENABLE_CMD_VIID(viid));
1177 cmd.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN |
1178 FW_VI_MAC_CMD_HASHUNIEN(ucast) |
1179 FW_CMD_LEN16(len16));
1180 cmd.u.hash.hashvec = cpu_to_be64(vec);
1181 return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
1185 * t4vf_get_port_stats - collect "port" statistics
1186 * @adapter: the adapter
1187 * @pidx: the port index
1188 * @s: the stats structure to fill
1190 * Collect statistics for the "port"'s Virtual Interface.
1192 int t4vf_get_port_stats(struct adapter *adapter, int pidx,
1193 struct t4vf_port_stats *s)
1195 struct port_info *pi = adap2pinfo(adapter, pidx);
1196 struct fw_vi_stats_vf fwstats;
1197 unsigned int rem = VI_VF_NUM_STATS;
1198 __be64 *fwsp = (__be64 *)&fwstats;
1201 * Grab the Virtual Interface statistics a chunk at a time via mailbox
1202 * commands. We could use a Work Request and get all of them at once
1203 * but that's an asynchronous interface which is awkward to use.
1206 unsigned int ix = VI_VF_NUM_STATS - rem;
1207 unsigned int nstats = min(6U, rem);
1208 struct fw_vi_stats_cmd cmd, rpl;
1209 size_t len = (offsetof(struct fw_vi_stats_cmd, u) +
1210 sizeof(struct fw_vi_stats_ctl));
1211 size_t len16 = DIV_ROUND_UP(len, 16);
1214 memset(&cmd, 0, sizeof(cmd));
1215 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_STATS_CMD) |
1216 FW_VI_STATS_CMD_VIID(pi->viid) |
1219 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
1220 cmd.u.ctl.nstats_ix =
1221 cpu_to_be16(FW_VI_STATS_CMD_IX(ix) |
1222 FW_VI_STATS_CMD_NSTATS(nstats));
1223 ret = t4vf_wr_mbox_ns(adapter, &cmd, len, &rpl);
1227 memcpy(fwsp, &rpl.u.ctl.stat0, sizeof(__be64) * nstats);
1234 * Translate firmware statistics into host native statistics.
1236 s->tx_bcast_bytes = be64_to_cpu(fwstats.tx_bcast_bytes);
1237 s->tx_bcast_frames = be64_to_cpu(fwstats.tx_bcast_frames);
1238 s->tx_mcast_bytes = be64_to_cpu(fwstats.tx_mcast_bytes);
1239 s->tx_mcast_frames = be64_to_cpu(fwstats.tx_mcast_frames);
1240 s->tx_ucast_bytes = be64_to_cpu(fwstats.tx_ucast_bytes);
1241 s->tx_ucast_frames = be64_to_cpu(fwstats.tx_ucast_frames);
1242 s->tx_drop_frames = be64_to_cpu(fwstats.tx_drop_frames);
1243 s->tx_offload_bytes = be64_to_cpu(fwstats.tx_offload_bytes);
1244 s->tx_offload_frames = be64_to_cpu(fwstats.tx_offload_frames);
1246 s->rx_bcast_bytes = be64_to_cpu(fwstats.rx_bcast_bytes);
1247 s->rx_bcast_frames = be64_to_cpu(fwstats.rx_bcast_frames);
1248 s->rx_mcast_bytes = be64_to_cpu(fwstats.rx_mcast_bytes);
1249 s->rx_mcast_frames = be64_to_cpu(fwstats.rx_mcast_frames);
1250 s->rx_ucast_bytes = be64_to_cpu(fwstats.rx_ucast_bytes);
1251 s->rx_ucast_frames = be64_to_cpu(fwstats.rx_ucast_frames);
1253 s->rx_err_frames = be64_to_cpu(fwstats.rx_err_frames);
1259 * t4vf_iq_free - free an ingress queue and its free lists
1260 * @adapter: the adapter
1261 * @iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
1262 * @iqid: ingress queue ID
1263 * @fl0id: FL0 queue ID or 0xffff if no attached FL0
1264 * @fl1id: FL1 queue ID or 0xffff if no attached FL1
1266 * Frees an ingress queue and its associated free lists, if any.
1268 int t4vf_iq_free(struct adapter *adapter, unsigned int iqtype,
1269 unsigned int iqid, unsigned int fl0id, unsigned int fl1id)
1271 struct fw_iq_cmd cmd;
1273 memset(&cmd, 0, sizeof(cmd));
1274 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_IQ_CMD) |
1277 cmd.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE |
1279 cmd.type_to_iqandstindex =
1280 cpu_to_be32(FW_IQ_CMD_TYPE(iqtype));
1282 cmd.iqid = cpu_to_be16(iqid);
1283 cmd.fl0id = cpu_to_be16(fl0id);
1284 cmd.fl1id = cpu_to_be16(fl1id);
1285 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
1289 * t4vf_eth_eq_free - free an Ethernet egress queue
1290 * @adapter: the adapter
1291 * @eqid: egress queue ID
1293 * Frees an Ethernet egress queue.
1295 int t4vf_eth_eq_free(struct adapter *adapter, unsigned int eqid)
1297 struct fw_eq_eth_cmd cmd;
1299 memset(&cmd, 0, sizeof(cmd));
1300 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_EQ_ETH_CMD) |
1303 cmd.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE |
1305 cmd.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID(eqid));
1306 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
1310 * t4vf_handle_fw_rpl - process a firmware reply message
1311 * @adapter: the adapter
1312 * @rpl: start of the firmware message
1314 * Processes a firmware message, such as link state change messages.
1316 int t4vf_handle_fw_rpl(struct adapter *adapter, const __be64 *rpl)
1318 const struct fw_cmd_hdr *cmd_hdr = (const struct fw_cmd_hdr *)rpl;
1319 u8 opcode = FW_CMD_OP_GET(be32_to_cpu(cmd_hdr->hi));
1324 * Link/module state change message.
1326 const struct fw_port_cmd *port_cmd =
1327 (const struct fw_port_cmd *)rpl;
1329 int action, port_id, link_ok, speed, fc, pidx;
1332 * Extract various fields from port status change message.
1334 action = FW_PORT_CMD_ACTION_GET(
1335 be32_to_cpu(port_cmd->action_to_len16));
1336 if (action != FW_PORT_ACTION_GET_PORT_INFO) {
1337 dev_err(adapter->pdev_dev,
1338 "Unknown firmware PORT reply action %x\n",
1343 port_id = FW_PORT_CMD_PORTID_GET(
1344 be32_to_cpu(port_cmd->op_to_portid));
1346 word = be32_to_cpu(port_cmd->u.info.lstatus_to_modtype);
1347 link_ok = (word & FW_PORT_CMD_LSTATUS) != 0;
1350 if (word & FW_PORT_CMD_RXPAUSE)
1352 if (word & FW_PORT_CMD_TXPAUSE)
1354 if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
1356 else if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
1358 else if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
1359 speed = SPEED_10000;
1362 * Scan all of our "ports" (Virtual Interfaces) looking for
1363 * those bound to the physical port which has changed. If
1364 * our recorded state doesn't match the current state,
1365 * signal that change to the OS code.
1367 for_each_port(adapter, pidx) {
1368 struct port_info *pi = adap2pinfo(adapter, pidx);
1369 struct link_config *lc;
1371 if (pi->port_id != port_id)
1375 if (link_ok != lc->link_ok || speed != lc->speed ||
1377 /* something changed */
1378 lc->link_ok = link_ok;
1381 t4vf_os_link_changed(adapter, pidx, link_ok);
1388 dev_err(adapter->pdev_dev, "Unknown firmware reply %X\n",