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/version.h>
37 #include <linux/pci.h>
39 #include "t4vf_common.h"
40 #include "t4vf_defs.h"
42 #include "../cxgb4/t4_regs.h"
43 #include "../cxgb4/t4fw_api.h"
46 * Wait for the device to become ready (signified by our "who am I" register
47 * returning a value other than all 1's). Return an error if it doesn't
50 int __devinit t4vf_wait_dev_ready(struct adapter *adapter)
52 const u32 whoami = T4VF_PL_BASE_ADDR + PL_VF_WHOAMI;
53 const u32 notready1 = 0xffffffff;
54 const u32 notready2 = 0xeeeeeeee;
57 val = t4_read_reg(adapter, whoami);
58 if (val != notready1 && val != notready2)
61 val = t4_read_reg(adapter, whoami);
62 if (val != notready1 && val != notready2)
69 * Get the reply to a mailbox command and store it in @rpl in big-endian order
70 * (since the firmware data structures are specified in a big-endian layout).
72 static void get_mbox_rpl(struct adapter *adapter, __be64 *rpl, int size,
75 for ( ; size; size -= 8, mbox_data += 8)
76 *rpl++ = cpu_to_be64(t4_read_reg64(adapter, mbox_data));
80 * Dump contents of mailbox with a leading tag.
82 static void dump_mbox(struct adapter *adapter, const char *tag, u32 mbox_data)
84 dev_err(adapter->pdev_dev,
85 "mbox %s: %llx %llx %llx %llx %llx %llx %llx %llx\n", tag,
86 (unsigned long long)t4_read_reg64(adapter, mbox_data + 0),
87 (unsigned long long)t4_read_reg64(adapter, mbox_data + 8),
88 (unsigned long long)t4_read_reg64(adapter, mbox_data + 16),
89 (unsigned long long)t4_read_reg64(adapter, mbox_data + 24),
90 (unsigned long long)t4_read_reg64(adapter, mbox_data + 32),
91 (unsigned long long)t4_read_reg64(adapter, mbox_data + 40),
92 (unsigned long long)t4_read_reg64(adapter, mbox_data + 48),
93 (unsigned long long)t4_read_reg64(adapter, mbox_data + 56));
97 * t4vf_wr_mbox_core - send a command to FW through the mailbox
98 * @adapter: the adapter
99 * @cmd: the command to write
100 * @size: command length in bytes
101 * @rpl: where to optionally store the reply
102 * @sleep_ok: if true we may sleep while awaiting command completion
104 * Sends the given command to FW through the mailbox and waits for the
105 * FW to execute the command. If @rpl is not %NULL it is used to store
106 * the FW's reply to the command. The command and its optional reply
107 * are of the same length. FW can take up to 500 ms to respond.
108 * @sleep_ok determines whether we may sleep while awaiting the response.
109 * If sleeping is allowed we use progressive backoff otherwise we spin.
111 * The return value is 0 on success or a negative errno on failure. A
112 * failure can happen either because we are not able to execute the
113 * command or FW executes it but signals an error. In the latter case
114 * the return value is the error code indicated by FW (negated).
116 int t4vf_wr_mbox_core(struct adapter *adapter, const void *cmd, int size,
117 void *rpl, bool sleep_ok)
119 static int delay[] = {
120 1, 1, 3, 5, 10, 10, 20, 50, 100
124 int i, ms, delay_idx;
126 u32 mbox_data = T4VF_MBDATA_BASE_ADDR;
127 u32 mbox_ctl = T4VF_CIM_BASE_ADDR + CIM_VF_EXT_MAILBOX_CTRL;
130 * Commands must be multiples of 16 bytes in length and may not be
131 * larger than the size of the Mailbox Data register array.
133 if ((size % 16) != 0 ||
134 size > NUM_CIM_VF_MAILBOX_DATA_INSTANCES * 4)
138 * Loop trying to get ownership of the mailbox. Return an error
139 * if we can't gain ownership.
141 v = MBOWNER_GET(t4_read_reg(adapter, mbox_ctl));
142 for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
143 v = MBOWNER_GET(t4_read_reg(adapter, mbox_ctl));
144 if (v != MBOX_OWNER_DRV)
145 return v == MBOX_OWNER_FW ? -EBUSY : -ETIMEDOUT;
148 * Write the command array into the Mailbox Data register array and
149 * transfer ownership of the mailbox to the firmware.
151 for (i = 0, p = cmd; i < size; i += 8)
152 t4_write_reg64(adapter, mbox_data + i, be64_to_cpu(*p++));
153 t4_write_reg(adapter, mbox_ctl,
154 MBMSGVALID | MBOWNER(MBOX_OWNER_FW));
155 t4_read_reg(adapter, mbox_ctl); /* flush write */
158 * Spin waiting for firmware to acknowledge processing our command.
163 for (i = 0; i < 500; i += ms) {
165 ms = delay[delay_idx];
166 if (delay_idx < ARRAY_SIZE(delay) - 1)
173 * If we're the owner, see if this is the reply we wanted.
175 v = t4_read_reg(adapter, mbox_ctl);
176 if (MBOWNER_GET(v) == MBOX_OWNER_DRV) {
178 * If the Message Valid bit isn't on, revoke ownership
179 * of the mailbox and continue waiting for our reply.
181 if ((v & MBMSGVALID) == 0) {
182 t4_write_reg(adapter, mbox_ctl,
183 MBOWNER(MBOX_OWNER_NONE));
188 * We now have our reply. Extract the command return
189 * value, copy the reply back to our caller's buffer
190 * (if specified) and revoke ownership of the mailbox.
191 * We return the (negated) firmware command return
192 * code (this depends on FW_SUCCESS == 0).
195 /* return value in low-order little-endian word */
196 v = t4_read_reg(adapter, mbox_data);
197 if (FW_CMD_RETVAL_GET(v))
198 dump_mbox(adapter, "FW Error", mbox_data);
201 /* request bit in high-order BE word */
202 WARN_ON((be32_to_cpu(*(const u32 *)cmd)
203 & FW_CMD_REQUEST) == 0);
204 get_mbox_rpl(adapter, rpl, size, mbox_data);
205 WARN_ON((be32_to_cpu(*(u32 *)rpl)
206 & FW_CMD_REQUEST) != 0);
208 t4_write_reg(adapter, mbox_ctl,
209 MBOWNER(MBOX_OWNER_NONE));
210 return -FW_CMD_RETVAL_GET(v);
215 * We timed out. Return the error ...
217 dump_mbox(adapter, "FW Timeout", mbox_data);
222 * hash_mac_addr - return the hash value of a MAC address
223 * @addr: the 48-bit Ethernet MAC address
225 * Hashes a MAC address according to the hash function used by hardware
226 * inexact (hash) address matching.
228 static int hash_mac_addr(const u8 *addr)
230 u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
231 u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
239 * init_link_config - initialize a link's SW state
240 * @lc: structure holding the link state
241 * @caps: link capabilities
243 * Initializes the SW state maintained for each link, including the link's
244 * capabilities and default speed/flow-control/autonegotiation settings.
246 static void __devinit init_link_config(struct link_config *lc,
249 lc->supported = caps;
250 lc->requested_speed = 0;
252 lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
253 if (lc->supported & SUPPORTED_Autoneg) {
254 lc->advertising = lc->supported;
255 lc->autoneg = AUTONEG_ENABLE;
256 lc->requested_fc |= PAUSE_AUTONEG;
259 lc->autoneg = AUTONEG_DISABLE;
264 * t4vf_port_init - initialize port hardware/software state
265 * @adapter: the adapter
266 * @pidx: the adapter port index
268 int __devinit t4vf_port_init(struct adapter *adapter, int pidx)
270 struct port_info *pi = adap2pinfo(adapter, pidx);
271 struct fw_vi_cmd vi_cmd, vi_rpl;
272 struct fw_port_cmd port_cmd, port_rpl;
277 * Execute a VI Read command to get our Virtual Interface information
278 * like MAC address, etc.
280 memset(&vi_cmd, 0, sizeof(vi_cmd));
281 vi_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
284 vi_cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(vi_cmd));
285 vi_cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID(pi->viid));
286 v = t4vf_wr_mbox(adapter, &vi_cmd, sizeof(vi_cmd), &vi_rpl);
290 BUG_ON(pi->port_id != FW_VI_CMD_PORTID_GET(vi_rpl.portid_pkd));
291 pi->rss_size = FW_VI_CMD_RSSSIZE_GET(be16_to_cpu(vi_rpl.rsssize_pkd));
292 t4_os_set_hw_addr(adapter, pidx, vi_rpl.mac);
295 * If we don't have read access to our port information, we're done
296 * now. Otherwise, execute a PORT Read command to get it ...
298 if (!(adapter->params.vfres.r_caps & FW_CMD_CAP_PORT))
301 memset(&port_cmd, 0, sizeof(port_cmd));
302 port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP(FW_PORT_CMD) |
305 FW_PORT_CMD_PORTID(pi->port_id));
306 port_cmd.action_to_len16 =
307 cpu_to_be32(FW_PORT_CMD_ACTION(FW_PORT_ACTION_GET_PORT_INFO) |
309 v = t4vf_wr_mbox(adapter, &port_cmd, sizeof(port_cmd), &port_rpl);
314 word = be16_to_cpu(port_rpl.u.info.pcap);
315 if (word & FW_PORT_CAP_SPEED_100M)
316 v |= SUPPORTED_100baseT_Full;
317 if (word & FW_PORT_CAP_SPEED_1G)
318 v |= SUPPORTED_1000baseT_Full;
319 if (word & FW_PORT_CAP_SPEED_10G)
320 v |= SUPPORTED_10000baseT_Full;
321 if (word & FW_PORT_CAP_ANEG)
322 v |= SUPPORTED_Autoneg;
323 init_link_config(&pi->link_cfg, v);
329 * t4vf_fw_reset - issue a reset to FW
330 * @adapter: the adapter
332 * Issues a reset command to FW. For a Physical Function this would
333 * result in the Firmware reseting all of its state. For a Virtual
334 * Function this just resets the state associated with the VF.
336 int t4vf_fw_reset(struct adapter *adapter)
338 struct fw_reset_cmd cmd;
340 memset(&cmd, 0, sizeof(cmd));
341 cmd.op_to_write = cpu_to_be32(FW_CMD_OP(FW_RESET_CMD) |
343 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
344 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
348 * t4vf_query_params - query FW or device parameters
349 * @adapter: the adapter
350 * @nparams: the number of parameters
351 * @params: the parameter names
352 * @vals: the parameter values
354 * Reads the values of firmware or device parameters. Up to 7 parameters
355 * can be queried at once.
357 int t4vf_query_params(struct adapter *adapter, unsigned int nparams,
358 const u32 *params, u32 *vals)
361 struct fw_params_cmd cmd, rpl;
362 struct fw_params_param *p;
368 memset(&cmd, 0, sizeof(cmd));
369 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PARAMS_CMD) |
372 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
373 param[nparams].mnem), 16);
374 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
375 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++)
376 p->mnem = htonl(*params++);
378 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
380 for (i = 0, p = &rpl.param[0]; i < nparams; i++, p++)
381 *vals++ = be32_to_cpu(p->val);
386 * t4vf_set_params - sets FW or device parameters
387 * @adapter: the adapter
388 * @nparams: the number of parameters
389 * @params: the parameter names
390 * @vals: the parameter values
392 * Sets the values of firmware or device parameters. Up to 7 parameters
393 * can be specified at once.
395 int t4vf_set_params(struct adapter *adapter, unsigned int nparams,
396 const u32 *params, const u32 *vals)
399 struct fw_params_cmd cmd;
400 struct fw_params_param *p;
406 memset(&cmd, 0, sizeof(cmd));
407 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PARAMS_CMD) |
410 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
411 param[nparams]), 16);
412 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
413 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++) {
414 p->mnem = cpu_to_be32(*params++);
415 p->val = cpu_to_be32(*vals++);
418 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
422 * t4vf_get_sge_params - retrieve adapter Scatter gather Engine parameters
423 * @adapter: the adapter
425 * Retrieves various core SGE parameters in the form of hardware SGE
426 * register values. The caller is responsible for decoding these as
427 * needed. The SGE parameters are stored in @adapter->params.sge.
429 int t4vf_get_sge_params(struct adapter *adapter)
431 struct sge_params *sge_params = &adapter->params.sge;
432 u32 params[7], vals[7];
435 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
436 FW_PARAMS_PARAM_XYZ(SGE_CONTROL));
437 params[1] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
438 FW_PARAMS_PARAM_XYZ(SGE_HOST_PAGE_SIZE));
439 params[2] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
440 FW_PARAMS_PARAM_XYZ(SGE_FL_BUFFER_SIZE0));
441 params[3] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
442 FW_PARAMS_PARAM_XYZ(SGE_FL_BUFFER_SIZE1));
443 params[4] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
444 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_0_AND_1));
445 params[5] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
446 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_2_AND_3));
447 params[6] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
448 FW_PARAMS_PARAM_XYZ(SGE_TIMER_VALUE_4_AND_5));
449 v = t4vf_query_params(adapter, 7, params, vals);
452 sge_params->sge_control = vals[0];
453 sge_params->sge_host_page_size = vals[1];
454 sge_params->sge_fl_buffer_size[0] = vals[2];
455 sge_params->sge_fl_buffer_size[1] = vals[3];
456 sge_params->sge_timer_value_0_and_1 = vals[4];
457 sge_params->sge_timer_value_2_and_3 = vals[5];
458 sge_params->sge_timer_value_4_and_5 = vals[6];
460 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
461 FW_PARAMS_PARAM_XYZ(SGE_INGRESS_RX_THRESHOLD));
462 v = t4vf_query_params(adapter, 1, params, vals);
465 sge_params->sge_ingress_rx_threshold = vals[0];
471 * t4vf_get_vpd_params - retrieve device VPD paremeters
472 * @adapter: the adapter
474 * Retrives various device Vital Product Data parameters. The parameters
475 * are stored in @adapter->params.vpd.
477 int t4vf_get_vpd_params(struct adapter *adapter)
479 struct vpd_params *vpd_params = &adapter->params.vpd;
480 u32 params[7], vals[7];
483 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
484 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_CCLK));
485 v = t4vf_query_params(adapter, 1, params, vals);
488 vpd_params->cclk = vals[0];
494 * t4vf_get_dev_params - retrieve device paremeters
495 * @adapter: the adapter
497 * Retrives various device parameters. The parameters are stored in
498 * @adapter->params.dev.
500 int t4vf_get_dev_params(struct adapter *adapter)
502 struct dev_params *dev_params = &adapter->params.dev;
503 u32 params[7], vals[7];
506 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
507 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FWREV));
508 params[1] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
509 FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_TPREV));
510 v = t4vf_query_params(adapter, 2, params, vals);
513 dev_params->fwrev = vals[0];
514 dev_params->tprev = vals[1];
520 * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration
521 * @adapter: the adapter
523 * Retrieves global RSS mode and parameters with which we have to live
524 * and stores them in the @adapter's RSS parameters.
526 int t4vf_get_rss_glb_config(struct adapter *adapter)
528 struct rss_params *rss = &adapter->params.rss;
529 struct fw_rss_glb_config_cmd cmd, rpl;
533 * Execute an RSS Global Configuration read command to retrieve
534 * our RSS configuration.
536 memset(&cmd, 0, sizeof(cmd));
537 cmd.op_to_write = cpu_to_be32(FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
540 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
541 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
546 * Transate the big-endian RSS Global Configuration into our
547 * cpu-endian format based on the RSS mode. We also do first level
548 * filtering at this point to weed out modes which don't support
551 rss->mode = FW_RSS_GLB_CONFIG_CMD_MODE_GET(
552 be32_to_cpu(rpl.u.manual.mode_pkd));
554 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
555 u32 word = be32_to_cpu(
556 rpl.u.basicvirtual.synmapen_to_hashtoeplitz);
558 rss->u.basicvirtual.synmapen =
559 ((word & FW_RSS_GLB_CONFIG_CMD_SYNMAPEN) != 0);
560 rss->u.basicvirtual.syn4tupenipv6 =
561 ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV6) != 0);
562 rss->u.basicvirtual.syn2tupenipv6 =
563 ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV6) != 0);
564 rss->u.basicvirtual.syn4tupenipv4 =
565 ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV4) != 0);
566 rss->u.basicvirtual.syn2tupenipv4 =
567 ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV4) != 0);
569 rss->u.basicvirtual.ofdmapen =
570 ((word & FW_RSS_GLB_CONFIG_CMD_OFDMAPEN) != 0);
572 rss->u.basicvirtual.tnlmapen =
573 ((word & FW_RSS_GLB_CONFIG_CMD_TNLMAPEN) != 0);
574 rss->u.basicvirtual.tnlalllookup =
575 ((word & FW_RSS_GLB_CONFIG_CMD_TNLALLLKP) != 0);
577 rss->u.basicvirtual.hashtoeplitz =
578 ((word & FW_RSS_GLB_CONFIG_CMD_HASHTOEPLITZ) != 0);
580 /* we need at least Tunnel Map Enable to be set */
581 if (!rss->u.basicvirtual.tnlmapen)
587 /* all unknown/unsupported RSS modes result in an error */
595 * t4vf_get_vfres - retrieve VF resource limits
596 * @adapter: the adapter
598 * Retrieves configured resource limits and capabilities for a virtual
599 * function. The results are stored in @adapter->vfres.
601 int t4vf_get_vfres(struct adapter *adapter)
603 struct vf_resources *vfres = &adapter->params.vfres;
604 struct fw_pfvf_cmd cmd, rpl;
609 * Execute PFVF Read command to get VF resource limits; bail out early
610 * with error on command failure.
612 memset(&cmd, 0, sizeof(cmd));
613 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_PFVF_CMD) |
616 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
617 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
622 * Extract VF resource limits and return success.
624 word = be32_to_cpu(rpl.niqflint_niq);
625 vfres->niqflint = FW_PFVF_CMD_NIQFLINT_GET(word);
626 vfres->niq = FW_PFVF_CMD_NIQ_GET(word);
628 word = be32_to_cpu(rpl.type_to_neq);
629 vfres->neq = FW_PFVF_CMD_NEQ_GET(word);
630 vfres->pmask = FW_PFVF_CMD_PMASK_GET(word);
632 word = be32_to_cpu(rpl.tc_to_nexactf);
633 vfres->tc = FW_PFVF_CMD_TC_GET(word);
634 vfres->nvi = FW_PFVF_CMD_NVI_GET(word);
635 vfres->nexactf = FW_PFVF_CMD_NEXACTF_GET(word);
637 word = be32_to_cpu(rpl.r_caps_to_nethctrl);
638 vfres->r_caps = FW_PFVF_CMD_R_CAPS_GET(word);
639 vfres->wx_caps = FW_PFVF_CMD_WX_CAPS_GET(word);
640 vfres->nethctrl = FW_PFVF_CMD_NETHCTRL_GET(word);
646 * t4vf_read_rss_vi_config - read a VI's RSS configuration
647 * @adapter: the adapter
648 * @viid: Virtual Interface ID
649 * @config: pointer to host-native VI RSS Configuration buffer
651 * Reads the Virtual Interface's RSS configuration information and
652 * translates it into CPU-native format.
654 int t4vf_read_rss_vi_config(struct adapter *adapter, unsigned int viid,
655 union rss_vi_config *config)
657 struct fw_rss_vi_config_cmd cmd, rpl;
660 memset(&cmd, 0, sizeof(cmd));
661 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
664 FW_RSS_VI_CONFIG_CMD_VIID(viid));
665 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
666 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
670 switch (adapter->params.rss.mode) {
671 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
672 u32 word = be32_to_cpu(rpl.u.basicvirtual.defaultq_to_udpen);
674 config->basicvirtual.ip6fourtupen =
675 ((word & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN) != 0);
676 config->basicvirtual.ip6twotupen =
677 ((word & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN) != 0);
678 config->basicvirtual.ip4fourtupen =
679 ((word & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN) != 0);
680 config->basicvirtual.ip4twotupen =
681 ((word & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN) != 0);
682 config->basicvirtual.udpen =
683 ((word & FW_RSS_VI_CONFIG_CMD_UDPEN) != 0);
684 config->basicvirtual.defaultq =
685 FW_RSS_VI_CONFIG_CMD_DEFAULTQ_GET(word);
697 * t4vf_write_rss_vi_config - write a VI's RSS configuration
698 * @adapter: the adapter
699 * @viid: Virtual Interface ID
700 * @config: pointer to host-native VI RSS Configuration buffer
702 * Write the Virtual Interface's RSS configuration information
703 * (translating it into firmware-native format before writing).
705 int t4vf_write_rss_vi_config(struct adapter *adapter, unsigned int viid,
706 union rss_vi_config *config)
708 struct fw_rss_vi_config_cmd cmd, rpl;
710 memset(&cmd, 0, sizeof(cmd));
711 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
714 FW_RSS_VI_CONFIG_CMD_VIID(viid));
715 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
716 switch (adapter->params.rss.mode) {
717 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
720 if (config->basicvirtual.ip6fourtupen)
721 word |= FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
722 if (config->basicvirtual.ip6twotupen)
723 word |= FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
724 if (config->basicvirtual.ip4fourtupen)
725 word |= FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
726 if (config->basicvirtual.ip4twotupen)
727 word |= FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
728 if (config->basicvirtual.udpen)
729 word |= FW_RSS_VI_CONFIG_CMD_UDPEN;
730 word |= FW_RSS_VI_CONFIG_CMD_DEFAULTQ(
731 config->basicvirtual.defaultq);
732 cmd.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(word);
740 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
744 * t4vf_config_rss_range - configure a portion of the RSS mapping table
745 * @adapter: the adapter
746 * @viid: Virtual Interface of RSS Table Slice
747 * @start: starting entry in the table to write
748 * @n: how many table entries to write
749 * @rspq: values for the "Response Queue" (Ingress Queue) lookup table
750 * @nrspq: number of values in @rspq
752 * Programs the selected part of the VI's RSS mapping table with the
753 * provided values. If @nrspq < @n the supplied values are used repeatedly
754 * until the full table range is populated.
756 * The caller must ensure the values in @rspq are in the range 0..1023.
758 int t4vf_config_rss_range(struct adapter *adapter, unsigned int viid,
759 int start, int n, const u16 *rspq, int nrspq)
761 const u16 *rsp = rspq;
762 const u16 *rsp_end = rspq+nrspq;
763 struct fw_rss_ind_tbl_cmd cmd;
766 * Initialize firmware command template to write the RSS table.
768 memset(&cmd, 0, sizeof(cmd));
769 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_RSS_IND_TBL_CMD) |
772 FW_RSS_IND_TBL_CMD_VIID(viid));
773 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
776 * Each firmware RSS command can accommodate up to 32 RSS Ingress
777 * Queue Identifiers. These Ingress Queue IDs are packed three to
778 * a 32-bit word as 10-bit values with the upper remaining 2 bits
782 __be32 *qp = &cmd.iq0_to_iq2;
787 * Set up the firmware RSS command header to send the next
788 * "nq" Ingress Queue IDs to the firmware.
790 cmd.niqid = cpu_to_be16(nq);
791 cmd.startidx = cpu_to_be16(start);
794 * "nq" more done for the start of the next loop.
800 * While there are still Ingress Queue IDs to stuff into the
801 * current firmware RSS command, retrieve them from the
802 * Ingress Queue ID array and insert them into the command.
806 * Grab up to the next 3 Ingress Queue IDs (wrapping
807 * around the Ingress Queue ID array if necessary) and
808 * insert them into the firmware RSS command at the
809 * current 3-tuple position within the commad.
813 int nqbuf = min(3, nq);
816 qbuf[0] = qbuf[1] = qbuf[2] = 0;
823 *qp++ = cpu_to_be32(FW_RSS_IND_TBL_CMD_IQ0(qbuf[0]) |
824 FW_RSS_IND_TBL_CMD_IQ1(qbuf[1]) |
825 FW_RSS_IND_TBL_CMD_IQ2(qbuf[2]));
829 * Send this portion of the RRS table update to the firmware;
830 * bail out on any errors.
832 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
840 * t4vf_alloc_vi - allocate a virtual interface on a port
841 * @adapter: the adapter
842 * @port_id: physical port associated with the VI
844 * Allocate a new Virtual Interface and bind it to the indicated
845 * physical port. Return the new Virtual Interface Identifier on
846 * success, or a [negative] error number on failure.
848 int t4vf_alloc_vi(struct adapter *adapter, int port_id)
850 struct fw_vi_cmd cmd, rpl;
854 * Execute a VI command to allocate Virtual Interface and return its
857 memset(&cmd, 0, sizeof(cmd));
858 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
862 cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
864 cmd.portid_pkd = FW_VI_CMD_PORTID(port_id);
865 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
869 return FW_VI_CMD_VIID_GET(be16_to_cpu(rpl.type_viid));
873 * t4vf_free_vi -- free a virtual interface
874 * @adapter: the adapter
875 * @viid: the virtual interface identifier
877 * Free a previously allocated Virtual Interface. Return an error on
880 int t4vf_free_vi(struct adapter *adapter, int viid)
882 struct fw_vi_cmd cmd;
885 * Execute a VI command to free the Virtual Interface.
887 memset(&cmd, 0, sizeof(cmd));
888 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_VI_CMD) |
891 cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
893 cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID(viid));
894 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
898 * t4vf_enable_vi - enable/disable a virtual interface
899 * @adapter: the adapter
900 * @viid: the Virtual Interface ID
901 * @rx_en: 1=enable Rx, 0=disable Rx
902 * @tx_en: 1=enable Tx, 0=disable Tx
904 * Enables/disables a virtual interface.
906 int t4vf_enable_vi(struct adapter *adapter, unsigned int viid,
907 bool rx_en, bool tx_en)
909 struct fw_vi_enable_cmd cmd;
911 memset(&cmd, 0, sizeof(cmd));
912 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_ENABLE_CMD) |
915 FW_VI_ENABLE_CMD_VIID(viid));
916 cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN(rx_en) |
917 FW_VI_ENABLE_CMD_EEN(tx_en) |
919 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
923 * t4vf_identify_port - identify a VI's port by blinking its LED
924 * @adapter: the adapter
925 * @viid: the Virtual Interface ID
926 * @nblinks: how many times to blink LED at 2.5 Hz
928 * Identifies a VI's port by blinking its LED.
930 int t4vf_identify_port(struct adapter *adapter, unsigned int viid,
931 unsigned int nblinks)
933 struct fw_vi_enable_cmd cmd;
935 memset(&cmd, 0, sizeof(cmd));
936 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_ENABLE_CMD) |
939 FW_VI_ENABLE_CMD_VIID(viid));
940 cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED |
942 cmd.blinkdur = cpu_to_be16(nblinks);
943 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
947 * t4vf_set_rxmode - set Rx properties of a virtual interface
948 * @adapter: the adapter
950 * @mtu: the new MTU or -1 for no change
951 * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
952 * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
953 * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
954 * @vlanex: 1 to enable hardware VLAN Tag extraction, 0 to disable it,
957 * Sets Rx properties of a virtual interface.
959 int t4vf_set_rxmode(struct adapter *adapter, unsigned int viid,
960 int mtu, int promisc, int all_multi, int bcast, int vlanex,
963 struct fw_vi_rxmode_cmd cmd;
965 /* convert to FW values */
967 mtu = FW_VI_RXMODE_CMD_MTU_MASK;
969 promisc = FW_VI_RXMODE_CMD_PROMISCEN_MASK;
971 all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_MASK;
973 bcast = FW_VI_RXMODE_CMD_BROADCASTEN_MASK;
975 vlanex = FW_VI_RXMODE_CMD_VLANEXEN_MASK;
977 memset(&cmd, 0, sizeof(cmd));
978 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_RXMODE_CMD) |
981 FW_VI_RXMODE_CMD_VIID(viid));
982 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
983 cmd.mtu_to_vlanexen =
984 cpu_to_be32(FW_VI_RXMODE_CMD_MTU(mtu) |
985 FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
986 FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
987 FW_VI_RXMODE_CMD_BROADCASTEN(bcast) |
988 FW_VI_RXMODE_CMD_VLANEXEN(vlanex));
989 return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
993 * t4vf_alloc_mac_filt - allocates exact-match filters for MAC addresses
994 * @adapter: the adapter
995 * @viid: the Virtual Interface Identifier
996 * @free: if true any existing filters for this VI id are first removed
997 * @naddr: the number of MAC addresses to allocate filters for (up to 7)
998 * @addr: the MAC address(es)
999 * @idx: where to store the index of each allocated filter
1000 * @hash: pointer to hash address filter bitmap
1001 * @sleep_ok: call is allowed to sleep
1003 * Allocates an exact-match filter for each of the supplied addresses and
1004 * sets it to the corresponding address. If @idx is not %NULL it should
1005 * have at least @naddr entries, each of which will be set to the index of
1006 * the filter allocated for the corresponding MAC address. If a filter
1007 * could not be allocated for an address its index is set to 0xffff.
1008 * If @hash is not %NULL addresses that fail to allocate an exact filter
1009 * are hashed and update the hash filter bitmap pointed at by @hash.
1011 * Returns a negative error number or the number of filters allocated.
1013 int t4vf_alloc_mac_filt(struct adapter *adapter, unsigned int viid, bool free,
1014 unsigned int naddr, const u8 **addr, u16 *idx,
1015 u64 *hash, bool sleep_ok)
1018 struct fw_vi_mac_cmd cmd, rpl;
1019 struct fw_vi_mac_exact *p;
1022 if (naddr > ARRAY_SIZE(cmd.u.exact))
1024 len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1025 u.exact[naddr]), 16);
1027 memset(&cmd, 0, sizeof(cmd));
1028 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1031 (free ? FW_CMD_EXEC : 0) |
1032 FW_VI_MAC_CMD_VIID(viid));
1033 cmd.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_FREEMACS(free) |
1034 FW_CMD_LEN16(len16));
1036 for (i = 0, p = cmd.u.exact; i < naddr; i++, p++) {
1038 cpu_to_be16(FW_VI_MAC_CMD_VALID |
1039 FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
1040 memcpy(p->macaddr, addr[i], sizeof(p->macaddr));
1043 ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &rpl, sleep_ok);
1047 for (i = 0, p = rpl.u.exact; i < naddr; i++, p++) {
1048 u16 index = FW_VI_MAC_CMD_IDX_GET(be16_to_cpu(p->valid_to_idx));
1051 idx[i] = (index >= FW_CLS_TCAM_NUM_ENTRIES
1054 if (index < FW_CLS_TCAM_NUM_ENTRIES)
1057 *hash |= (1 << hash_mac_addr(addr[i]));
1063 * t4vf_change_mac - modifies the exact-match filter for a MAC address
1064 * @adapter: the adapter
1065 * @viid: the Virtual Interface ID
1066 * @idx: index of existing filter for old value of MAC address, or -1
1067 * @addr: the new MAC address value
1068 * @persist: if idx < 0, the new MAC allocation should be persistent
1070 * Modifies an exact-match filter and sets it to the new MAC address.
1071 * Note that in general it is not possible to modify the value of a given
1072 * filter so the generic way to modify an address filter is to free the
1073 * one being used by the old address value and allocate a new filter for
1074 * the new address value. @idx can be -1 if the address is a new
1077 * Returns a negative error number or the index of the filter with the new
1080 int t4vf_change_mac(struct adapter *adapter, unsigned int viid,
1081 int idx, const u8 *addr, bool persist)
1084 struct fw_vi_mac_cmd cmd, rpl;
1085 struct fw_vi_mac_exact *p = &cmd.u.exact[0];
1086 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1090 * If this is a new allocation, determine whether it should be
1091 * persistent (across a "freemacs" operation) or not.
1094 idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
1096 memset(&cmd, 0, sizeof(cmd));
1097 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1100 FW_VI_MAC_CMD_VIID(viid));
1101 cmd.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
1102 p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID |
1103 FW_VI_MAC_CMD_IDX(idx));
1104 memcpy(p->macaddr, addr, sizeof(p->macaddr));
1106 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
1108 p = &rpl.u.exact[0];
1109 ret = FW_VI_MAC_CMD_IDX_GET(be16_to_cpu(p->valid_to_idx));
1110 if (ret >= FW_CLS_TCAM_NUM_ENTRIES)
1117 * t4vf_set_addr_hash - program the MAC inexact-match hash filter
1118 * @adapter: the adapter
1119 * @viid: the Virtual Interface Identifier
1120 * @ucast: whether the hash filter should also match unicast addresses
1121 * @vec: the value to be written to the hash filter
1122 * @sleep_ok: call is allowed to sleep
1124 * Sets the 64-bit inexact-match hash filter for a virtual interface.
1126 int t4vf_set_addr_hash(struct adapter *adapter, unsigned int viid,
1127 bool ucast, u64 vec, bool sleep_ok)
1129 struct fw_vi_mac_cmd cmd;
1130 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1133 memset(&cmd, 0, sizeof(cmd));
1134 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1137 FW_VI_ENABLE_CMD_VIID(viid));
1138 cmd.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN |
1139 FW_VI_MAC_CMD_HASHUNIEN(ucast) |
1140 FW_CMD_LEN16(len16));
1141 cmd.u.hash.hashvec = cpu_to_be64(vec);
1142 return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
1146 * t4vf_get_port_stats - collect "port" statistics
1147 * @adapter: the adapter
1148 * @pidx: the port index
1149 * @s: the stats structure to fill
1151 * Collect statistics for the "port"'s Virtual Interface.
1153 int t4vf_get_port_stats(struct adapter *adapter, int pidx,
1154 struct t4vf_port_stats *s)
1156 struct port_info *pi = adap2pinfo(adapter, pidx);
1157 struct fw_vi_stats_vf fwstats;
1158 unsigned int rem = VI_VF_NUM_STATS;
1159 __be64 *fwsp = (__be64 *)&fwstats;
1162 * Grab the Virtual Interface statistics a chunk at a time via mailbox
1163 * commands. We could use a Work Request and get all of them at once
1164 * but that's an asynchronous interface which is awkward to use.
1167 unsigned int ix = VI_VF_NUM_STATS - rem;
1168 unsigned int nstats = min(6U, rem);
1169 struct fw_vi_stats_cmd cmd, rpl;
1170 size_t len = (offsetof(struct fw_vi_stats_cmd, u) +
1171 sizeof(struct fw_vi_stats_ctl));
1172 size_t len16 = DIV_ROUND_UP(len, 16);
1175 memset(&cmd, 0, sizeof(cmd));
1176 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_STATS_CMD) |
1177 FW_VI_STATS_CMD_VIID(pi->viid) |
1180 cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16(len16));
1181 cmd.u.ctl.nstats_ix =
1182 cpu_to_be16(FW_VI_STATS_CMD_IX(ix) |
1183 FW_VI_STATS_CMD_NSTATS(nstats));
1184 ret = t4vf_wr_mbox_ns(adapter, &cmd, len, &rpl);
1188 memcpy(fwsp, &rpl.u.ctl.stat0, sizeof(__be64) * nstats);
1195 * Translate firmware statistics into host native statistics.
1197 s->tx_bcast_bytes = be64_to_cpu(fwstats.tx_bcast_bytes);
1198 s->tx_bcast_frames = be64_to_cpu(fwstats.tx_bcast_frames);
1199 s->tx_mcast_bytes = be64_to_cpu(fwstats.tx_mcast_bytes);
1200 s->tx_mcast_frames = be64_to_cpu(fwstats.tx_mcast_frames);
1201 s->tx_ucast_bytes = be64_to_cpu(fwstats.tx_ucast_bytes);
1202 s->tx_ucast_frames = be64_to_cpu(fwstats.tx_ucast_frames);
1203 s->tx_drop_frames = be64_to_cpu(fwstats.tx_drop_frames);
1204 s->tx_offload_bytes = be64_to_cpu(fwstats.tx_offload_bytes);
1205 s->tx_offload_frames = be64_to_cpu(fwstats.tx_offload_frames);
1207 s->rx_bcast_bytes = be64_to_cpu(fwstats.rx_bcast_bytes);
1208 s->rx_bcast_frames = be64_to_cpu(fwstats.rx_bcast_frames);
1209 s->rx_mcast_bytes = be64_to_cpu(fwstats.rx_mcast_bytes);
1210 s->rx_mcast_frames = be64_to_cpu(fwstats.rx_mcast_frames);
1211 s->rx_ucast_bytes = be64_to_cpu(fwstats.rx_ucast_bytes);
1212 s->rx_ucast_frames = be64_to_cpu(fwstats.rx_ucast_frames);
1214 s->rx_err_frames = be64_to_cpu(fwstats.rx_err_frames);
1220 * t4vf_iq_free - free an ingress queue and its free lists
1221 * @adapter: the adapter
1222 * @iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
1223 * @iqid: ingress queue ID
1224 * @fl0id: FL0 queue ID or 0xffff if no attached FL0
1225 * @fl1id: FL1 queue ID or 0xffff if no attached FL1
1227 * Frees an ingress queue and its associated free lists, if any.
1229 int t4vf_iq_free(struct adapter *adapter, unsigned int iqtype,
1230 unsigned int iqid, unsigned int fl0id, unsigned int fl1id)
1232 struct fw_iq_cmd cmd;
1234 memset(&cmd, 0, sizeof(cmd));
1235 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_IQ_CMD) |
1238 cmd.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE |
1240 cmd.type_to_iqandstindex =
1241 cpu_to_be32(FW_IQ_CMD_TYPE(iqtype));
1243 cmd.iqid = cpu_to_be16(iqid);
1244 cmd.fl0id = cpu_to_be16(fl0id);
1245 cmd.fl1id = cpu_to_be16(fl1id);
1246 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
1250 * t4vf_eth_eq_free - free an Ethernet egress queue
1251 * @adapter: the adapter
1252 * @eqid: egress queue ID
1254 * Frees an Ethernet egress queue.
1256 int t4vf_eth_eq_free(struct adapter *adapter, unsigned int eqid)
1258 struct fw_eq_eth_cmd cmd;
1260 memset(&cmd, 0, sizeof(cmd));
1261 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP(FW_EQ_ETH_CMD) |
1264 cmd.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE |
1266 cmd.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID(eqid));
1267 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
1271 * t4vf_handle_fw_rpl - process a firmware reply message
1272 * @adapter: the adapter
1273 * @rpl: start of the firmware message
1275 * Processes a firmware message, such as link state change messages.
1277 int t4vf_handle_fw_rpl(struct adapter *adapter, const __be64 *rpl)
1279 struct fw_cmd_hdr *cmd_hdr = (struct fw_cmd_hdr *)rpl;
1280 u8 opcode = FW_CMD_OP_GET(be32_to_cpu(cmd_hdr->hi));
1285 * Link/module state change message.
1287 const struct fw_port_cmd *port_cmd = (void *)rpl;
1289 int action, port_id, link_ok, speed, fc, pidx;
1292 * Extract various fields from port status change message.
1294 action = FW_PORT_CMD_ACTION_GET(
1295 be32_to_cpu(port_cmd->action_to_len16));
1296 if (action != FW_PORT_ACTION_GET_PORT_INFO) {
1297 dev_err(adapter->pdev_dev,
1298 "Unknown firmware PORT reply action %x\n",
1303 port_id = FW_PORT_CMD_PORTID_GET(
1304 be32_to_cpu(port_cmd->op_to_portid));
1306 word = be32_to_cpu(port_cmd->u.info.lstatus_to_modtype);
1307 link_ok = (word & FW_PORT_CMD_LSTATUS) != 0;
1310 if (word & FW_PORT_CMD_RXPAUSE)
1312 if (word & FW_PORT_CMD_TXPAUSE)
1314 if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
1316 else if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
1318 else if (word & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
1319 speed = SPEED_10000;
1322 * Scan all of our "ports" (Virtual Interfaces) looking for
1323 * those bound to the physical port which has changed. If
1324 * our recorded state doesn't match the current state,
1325 * signal that change to the OS code.
1327 for_each_port(adapter, pidx) {
1328 struct port_info *pi = adap2pinfo(adapter, pidx);
1329 struct link_config *lc;
1331 if (pi->port_id != port_id)
1335 if (link_ok != lc->link_ok || speed != lc->speed ||
1337 /* something changed */
1338 lc->link_ok = link_ok;
1341 t4vf_os_link_changed(adapter, pidx, link_ok);
1348 dev_err(adapter->pdev_dev, "Unknown firmware reply %X\n",