2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/sched.h>
36 #include <linux/slab.h>
37 #include <linux/export.h>
38 #include <linux/pci.h>
39 #include <linux/errno.h>
41 #include <linux/mlx4/cmd.h>
42 #include <linux/mlx4/device.h>
43 #include <linux/semaphore.h>
44 #include <rdma/ib_smi.h>
51 #define CMD_POLL_TOKEN 0xffff
52 #define INBOX_MASK 0xffffffffffffff00ULL
54 #define CMD_CHAN_VER 1
55 #define CMD_CHAN_IF_REV 1
58 /* command completed successfully: */
60 /* Internal error (such as a bus error) occurred while processing command: */
61 CMD_STAT_INTERNAL_ERR
= 0x01,
62 /* Operation/command not supported or opcode modifier not supported: */
63 CMD_STAT_BAD_OP
= 0x02,
64 /* Parameter not supported or parameter out of range: */
65 CMD_STAT_BAD_PARAM
= 0x03,
66 /* System not enabled or bad system state: */
67 CMD_STAT_BAD_SYS_STATE
= 0x04,
68 /* Attempt to access reserved or unallocaterd resource: */
69 CMD_STAT_BAD_RESOURCE
= 0x05,
70 /* Requested resource is currently executing a command, or is otherwise busy: */
71 CMD_STAT_RESOURCE_BUSY
= 0x06,
72 /* Required capability exceeds device limits: */
73 CMD_STAT_EXCEED_LIM
= 0x08,
74 /* Resource is not in the appropriate state or ownership: */
75 CMD_STAT_BAD_RES_STATE
= 0x09,
76 /* Index out of range: */
77 CMD_STAT_BAD_INDEX
= 0x0a,
78 /* FW image corrupted: */
79 CMD_STAT_BAD_NVMEM
= 0x0b,
80 /* Error in ICM mapping (e.g. not enough auxiliary ICM pages to execute command): */
81 CMD_STAT_ICM_ERROR
= 0x0c,
82 /* Attempt to modify a QP/EE which is not in the presumed state: */
83 CMD_STAT_BAD_QP_STATE
= 0x10,
84 /* Bad segment parameters (Address/Size): */
85 CMD_STAT_BAD_SEG_PARAM
= 0x20,
86 /* Memory Region has Memory Windows bound to: */
87 CMD_STAT_REG_BOUND
= 0x21,
88 /* HCA local attached memory not present: */
89 CMD_STAT_LAM_NOT_PRE
= 0x22,
90 /* Bad management packet (silently discarded): */
91 CMD_STAT_BAD_PKT
= 0x30,
92 /* More outstanding CQEs in CQ than new CQ size: */
93 CMD_STAT_BAD_SIZE
= 0x40,
94 /* Multi Function device support required: */
95 CMD_STAT_MULTI_FUNC_REQ
= 0x50,
99 HCR_IN_PARAM_OFFSET
= 0x00,
100 HCR_IN_MODIFIER_OFFSET
= 0x08,
101 HCR_OUT_PARAM_OFFSET
= 0x0c,
102 HCR_TOKEN_OFFSET
= 0x14,
103 HCR_STATUS_OFFSET
= 0x18,
105 HCR_OPMOD_SHIFT
= 12,
112 GO_BIT_TIMEOUT_MSECS
= 10000
115 struct mlx4_cmd_context
{
116 struct completion done
;
124 static int mlx4_master_process_vhcr(struct mlx4_dev
*dev
, int slave
,
125 struct mlx4_vhcr_cmd
*in_vhcr
);
127 static int mlx4_status_to_errno(u8 status
)
129 static const int trans_table
[] = {
130 [CMD_STAT_INTERNAL_ERR
] = -EIO
,
131 [CMD_STAT_BAD_OP
] = -EPERM
,
132 [CMD_STAT_BAD_PARAM
] = -EINVAL
,
133 [CMD_STAT_BAD_SYS_STATE
] = -ENXIO
,
134 [CMD_STAT_BAD_RESOURCE
] = -EBADF
,
135 [CMD_STAT_RESOURCE_BUSY
] = -EBUSY
,
136 [CMD_STAT_EXCEED_LIM
] = -ENOMEM
,
137 [CMD_STAT_BAD_RES_STATE
] = -EBADF
,
138 [CMD_STAT_BAD_INDEX
] = -EBADF
,
139 [CMD_STAT_BAD_NVMEM
] = -EFAULT
,
140 [CMD_STAT_ICM_ERROR
] = -ENFILE
,
141 [CMD_STAT_BAD_QP_STATE
] = -EINVAL
,
142 [CMD_STAT_BAD_SEG_PARAM
] = -EFAULT
,
143 [CMD_STAT_REG_BOUND
] = -EBUSY
,
144 [CMD_STAT_LAM_NOT_PRE
] = -EAGAIN
,
145 [CMD_STAT_BAD_PKT
] = -EINVAL
,
146 [CMD_STAT_BAD_SIZE
] = -ENOMEM
,
147 [CMD_STAT_MULTI_FUNC_REQ
] = -EACCES
,
150 if (status
>= ARRAY_SIZE(trans_table
) ||
151 (status
!= CMD_STAT_OK
&& trans_table
[status
] == 0))
154 return trans_table
[status
];
157 static u8
mlx4_errno_to_status(int errno
)
161 return CMD_STAT_BAD_OP
;
163 return CMD_STAT_BAD_PARAM
;
165 return CMD_STAT_BAD_SYS_STATE
;
167 return CMD_STAT_RESOURCE_BUSY
;
169 return CMD_STAT_EXCEED_LIM
;
171 return CMD_STAT_ICM_ERROR
;
173 return CMD_STAT_INTERNAL_ERR
;
177 static int comm_pending(struct mlx4_dev
*dev
)
179 struct mlx4_priv
*priv
= mlx4_priv(dev
);
180 u32 status
= readl(&priv
->mfunc
.comm
->slave_read
);
182 return (swab32(status
) >> 31) != priv
->cmd
.comm_toggle
;
185 static void mlx4_comm_cmd_post(struct mlx4_dev
*dev
, u8 cmd
, u16 param
)
187 struct mlx4_priv
*priv
= mlx4_priv(dev
);
190 priv
->cmd
.comm_toggle
^= 1;
191 val
= param
| (cmd
<< 16) | (priv
->cmd
.comm_toggle
<< 31);
192 __raw_writel((__force u32
) cpu_to_be32(val
),
193 &priv
->mfunc
.comm
->slave_write
);
197 static int mlx4_comm_cmd_poll(struct mlx4_dev
*dev
, u8 cmd
, u16 param
,
198 unsigned long timeout
)
200 struct mlx4_priv
*priv
= mlx4_priv(dev
);
203 int ret_from_pending
= 0;
205 /* First, verify that the master reports correct status */
206 if (comm_pending(dev
)) {
207 mlx4_warn(dev
, "Communication channel is not idle."
208 "my toggle is %d (cmd:0x%x)\n",
209 priv
->cmd
.comm_toggle
, cmd
);
214 down(&priv
->cmd
.poll_sem
);
215 mlx4_comm_cmd_post(dev
, cmd
, param
);
217 end
= msecs_to_jiffies(timeout
) + jiffies
;
218 while (comm_pending(dev
) && time_before(jiffies
, end
))
220 ret_from_pending
= comm_pending(dev
);
221 if (ret_from_pending
) {
222 /* check if the slave is trying to boot in the middle of
223 * FLR process. The only non-zero result in the RESET command
224 * is MLX4_DELAY_RESET_SLAVE*/
225 if ((MLX4_COMM_CMD_RESET
== cmd
)) {
226 err
= MLX4_DELAY_RESET_SLAVE
;
228 mlx4_warn(dev
, "Communication channel timed out\n");
233 up(&priv
->cmd
.poll_sem
);
237 static int mlx4_comm_cmd_wait(struct mlx4_dev
*dev
, u8 op
,
238 u16 param
, unsigned long timeout
)
240 struct mlx4_cmd
*cmd
= &mlx4_priv(dev
)->cmd
;
241 struct mlx4_cmd_context
*context
;
245 down(&cmd
->event_sem
);
247 spin_lock(&cmd
->context_lock
);
248 BUG_ON(cmd
->free_head
< 0);
249 context
= &cmd
->context
[cmd
->free_head
];
250 context
->token
+= cmd
->token_mask
+ 1;
251 cmd
->free_head
= context
->next
;
252 spin_unlock(&cmd
->context_lock
);
254 init_completion(&context
->done
);
256 mlx4_comm_cmd_post(dev
, op
, param
);
258 if (!wait_for_completion_timeout(&context
->done
,
259 msecs_to_jiffies(timeout
))) {
260 mlx4_warn(dev
, "communication channel command 0x%x timed out\n",
266 err
= context
->result
;
267 if (err
&& context
->fw_status
!= CMD_STAT_MULTI_FUNC_REQ
) {
268 mlx4_err(dev
, "command 0x%x failed: fw status = 0x%x\n",
269 op
, context
->fw_status
);
274 /* wait for comm channel ready
275 * this is necessary for prevention the race
276 * when switching between event to polling mode
278 end
= msecs_to_jiffies(timeout
) + jiffies
;
279 while (comm_pending(dev
) && time_before(jiffies
, end
))
282 spin_lock(&cmd
->context_lock
);
283 context
->next
= cmd
->free_head
;
284 cmd
->free_head
= context
- cmd
->context
;
285 spin_unlock(&cmd
->context_lock
);
291 int mlx4_comm_cmd(struct mlx4_dev
*dev
, u8 cmd
, u16 param
,
292 unsigned long timeout
)
294 if (mlx4_priv(dev
)->cmd
.use_events
)
295 return mlx4_comm_cmd_wait(dev
, cmd
, param
, timeout
);
296 return mlx4_comm_cmd_poll(dev
, cmd
, param
, timeout
);
299 static int cmd_pending(struct mlx4_dev
*dev
)
303 if (pci_channel_offline(dev
->pdev
))
306 status
= readl(mlx4_priv(dev
)->cmd
.hcr
+ HCR_STATUS_OFFSET
);
308 return (status
& swab32(1 << HCR_GO_BIT
)) ||
309 (mlx4_priv(dev
)->cmd
.toggle
==
310 !!(status
& swab32(1 << HCR_T_BIT
)));
313 static int mlx4_cmd_post(struct mlx4_dev
*dev
, u64 in_param
, u64 out_param
,
314 u32 in_modifier
, u8 op_modifier
, u16 op
, u16 token
,
317 struct mlx4_cmd
*cmd
= &mlx4_priv(dev
)->cmd
;
318 u32 __iomem
*hcr
= cmd
->hcr
;
322 mutex_lock(&cmd
->hcr_mutex
);
324 if (pci_channel_offline(dev
->pdev
)) {
326 * Device is going through error recovery
327 * and cannot accept commands.
335 end
+= msecs_to_jiffies(GO_BIT_TIMEOUT_MSECS
);
337 while (cmd_pending(dev
)) {
338 if (pci_channel_offline(dev
->pdev
)) {
340 * Device is going through error recovery
341 * and cannot accept commands.
347 if (time_after_eq(jiffies
, end
)) {
348 mlx4_err(dev
, "%s:cmd_pending failed\n", __func__
);
355 * We use writel (instead of something like memcpy_toio)
356 * because writes of less than 32 bits to the HCR don't work
357 * (and some architectures such as ia64 implement memcpy_toio
358 * in terms of writeb).
360 __raw_writel((__force u32
) cpu_to_be32(in_param
>> 32), hcr
+ 0);
361 __raw_writel((__force u32
) cpu_to_be32(in_param
& 0xfffffffful
), hcr
+ 1);
362 __raw_writel((__force u32
) cpu_to_be32(in_modifier
), hcr
+ 2);
363 __raw_writel((__force u32
) cpu_to_be32(out_param
>> 32), hcr
+ 3);
364 __raw_writel((__force u32
) cpu_to_be32(out_param
& 0xfffffffful
), hcr
+ 4);
365 __raw_writel((__force u32
) cpu_to_be32(token
<< 16), hcr
+ 5);
367 /* __raw_writel may not order writes. */
370 __raw_writel((__force u32
) cpu_to_be32((1 << HCR_GO_BIT
) |
371 (cmd
->toggle
<< HCR_T_BIT
) |
372 (event
? (1 << HCR_E_BIT
) : 0) |
373 (op_modifier
<< HCR_OPMOD_SHIFT
) |
377 * Make sure that our HCR writes don't get mixed in with
378 * writes from another CPU starting a FW command.
382 cmd
->toggle
= cmd
->toggle
^ 1;
387 mutex_unlock(&cmd
->hcr_mutex
);
391 static int mlx4_slave_cmd(struct mlx4_dev
*dev
, u64 in_param
, u64
*out_param
,
392 int out_is_imm
, u32 in_modifier
, u8 op_modifier
,
393 u16 op
, unsigned long timeout
)
395 struct mlx4_priv
*priv
= mlx4_priv(dev
);
396 struct mlx4_vhcr_cmd
*vhcr
= priv
->mfunc
.vhcr
;
399 mutex_lock(&priv
->cmd
.slave_cmd_mutex
);
401 vhcr
->in_param
= cpu_to_be64(in_param
);
402 vhcr
->out_param
= out_param
? cpu_to_be64(*out_param
) : 0;
403 vhcr
->in_modifier
= cpu_to_be32(in_modifier
);
404 vhcr
->opcode
= cpu_to_be16((((u16
) op_modifier
) << 12) | (op
& 0xfff));
405 vhcr
->token
= cpu_to_be16(CMD_POLL_TOKEN
);
407 vhcr
->flags
= !!(priv
->cmd
.use_events
) << 6;
409 if (mlx4_is_master(dev
)) {
410 ret
= mlx4_master_process_vhcr(dev
, dev
->caps
.function
, vhcr
);
415 be64_to_cpu(vhcr
->out_param
);
417 mlx4_err(dev
, "response expected while"
418 "output mailbox is NULL for "
419 "command 0x%x\n", op
);
420 vhcr
->status
= CMD_STAT_BAD_PARAM
;
423 ret
= mlx4_status_to_errno(vhcr
->status
);
426 ret
= mlx4_comm_cmd(dev
, MLX4_COMM_CMD_VHCR_POST
, 0,
427 MLX4_COMM_TIME
+ timeout
);
432 be64_to_cpu(vhcr
->out_param
);
434 mlx4_err(dev
, "response expected while"
435 "output mailbox is NULL for "
436 "command 0x%x\n", op
);
437 vhcr
->status
= CMD_STAT_BAD_PARAM
;
440 ret
= mlx4_status_to_errno(vhcr
->status
);
442 mlx4_err(dev
, "failed execution of VHCR_POST command"
443 "opcode 0x%x\n", op
);
446 mutex_unlock(&priv
->cmd
.slave_cmd_mutex
);
450 static int mlx4_cmd_poll(struct mlx4_dev
*dev
, u64 in_param
, u64
*out_param
,
451 int out_is_imm
, u32 in_modifier
, u8 op_modifier
,
452 u16 op
, unsigned long timeout
)
454 struct mlx4_priv
*priv
= mlx4_priv(dev
);
455 void __iomem
*hcr
= priv
->cmd
.hcr
;
460 down(&priv
->cmd
.poll_sem
);
462 if (pci_channel_offline(dev
->pdev
)) {
464 * Device is going through error recovery
465 * and cannot accept commands.
471 err
= mlx4_cmd_post(dev
, in_param
, out_param
? *out_param
: 0,
472 in_modifier
, op_modifier
, op
, CMD_POLL_TOKEN
, 0);
476 end
= msecs_to_jiffies(timeout
) + jiffies
;
477 while (cmd_pending(dev
) && time_before(jiffies
, end
)) {
478 if (pci_channel_offline(dev
->pdev
)) {
480 * Device is going through error recovery
481 * and cannot accept commands.
490 if (cmd_pending(dev
)) {
491 mlx4_warn(dev
, "command 0x%x timed out (go bit not cleared)\n",
499 (u64
) be32_to_cpu((__force __be32
)
500 __raw_readl(hcr
+ HCR_OUT_PARAM_OFFSET
)) << 32 |
501 (u64
) be32_to_cpu((__force __be32
)
502 __raw_readl(hcr
+ HCR_OUT_PARAM_OFFSET
+ 4));
503 stat
= be32_to_cpu((__force __be32
)
504 __raw_readl(hcr
+ HCR_STATUS_OFFSET
)) >> 24;
505 err
= mlx4_status_to_errno(stat
);
507 mlx4_err(dev
, "command 0x%x failed: fw status = 0x%x\n",
511 up(&priv
->cmd
.poll_sem
);
515 void mlx4_cmd_event(struct mlx4_dev
*dev
, u16 token
, u8 status
, u64 out_param
)
517 struct mlx4_priv
*priv
= mlx4_priv(dev
);
518 struct mlx4_cmd_context
*context
=
519 &priv
->cmd
.context
[token
& priv
->cmd
.token_mask
];
521 /* previously timed out command completing at long last */
522 if (token
!= context
->token
)
525 context
->fw_status
= status
;
526 context
->result
= mlx4_status_to_errno(status
);
527 context
->out_param
= out_param
;
529 complete(&context
->done
);
532 static int mlx4_cmd_wait(struct mlx4_dev
*dev
, u64 in_param
, u64
*out_param
,
533 int out_is_imm
, u32 in_modifier
, u8 op_modifier
,
534 u16 op
, unsigned long timeout
)
536 struct mlx4_cmd
*cmd
= &mlx4_priv(dev
)->cmd
;
537 struct mlx4_cmd_context
*context
;
540 down(&cmd
->event_sem
);
542 spin_lock(&cmd
->context_lock
);
543 BUG_ON(cmd
->free_head
< 0);
544 context
= &cmd
->context
[cmd
->free_head
];
545 context
->token
+= cmd
->token_mask
+ 1;
546 cmd
->free_head
= context
->next
;
547 spin_unlock(&cmd
->context_lock
);
549 init_completion(&context
->done
);
551 mlx4_cmd_post(dev
, in_param
, out_param
? *out_param
: 0,
552 in_modifier
, op_modifier
, op
, context
->token
, 1);
554 if (!wait_for_completion_timeout(&context
->done
,
555 msecs_to_jiffies(timeout
))) {
556 mlx4_warn(dev
, "command 0x%x timed out (go bit not cleared)\n",
562 err
= context
->result
;
564 mlx4_err(dev
, "command 0x%x failed: fw status = 0x%x\n",
565 op
, context
->fw_status
);
570 *out_param
= context
->out_param
;
573 spin_lock(&cmd
->context_lock
);
574 context
->next
= cmd
->free_head
;
575 cmd
->free_head
= context
- cmd
->context
;
576 spin_unlock(&cmd
->context_lock
);
582 int __mlx4_cmd(struct mlx4_dev
*dev
, u64 in_param
, u64
*out_param
,
583 int out_is_imm
, u32 in_modifier
, u8 op_modifier
,
584 u16 op
, unsigned long timeout
, int native
)
586 if (pci_channel_offline(dev
->pdev
))
589 if (!mlx4_is_mfunc(dev
) || (native
&& mlx4_is_master(dev
))) {
590 if (mlx4_priv(dev
)->cmd
.use_events
)
591 return mlx4_cmd_wait(dev
, in_param
, out_param
,
592 out_is_imm
, in_modifier
,
593 op_modifier
, op
, timeout
);
595 return mlx4_cmd_poll(dev
, in_param
, out_param
,
596 out_is_imm
, in_modifier
,
597 op_modifier
, op
, timeout
);
599 return mlx4_slave_cmd(dev
, in_param
, out_param
, out_is_imm
,
600 in_modifier
, op_modifier
, op
, timeout
);
602 EXPORT_SYMBOL_GPL(__mlx4_cmd
);
605 static int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev
*dev
)
607 return mlx4_cmd(dev
, 0, 0, 0, MLX4_CMD_ARM_COMM_CHANNEL
,
608 MLX4_CMD_TIME_CLASS_B
, MLX4_CMD_NATIVE
);
611 static int mlx4_ACCESS_MEM(struct mlx4_dev
*dev
, u64 master_addr
,
612 int slave
, u64 slave_addr
,
613 int size
, int is_read
)
618 if ((slave_addr
& 0xfff) | (master_addr
& 0xfff) |
619 (slave
& ~0x7f) | (size
& 0xff)) {
620 mlx4_err(dev
, "Bad access mem params - slave_addr:0x%llx "
621 "master_addr:0x%llx slave_id:%d size:%d\n",
622 slave_addr
, master_addr
, slave
, size
);
627 in_param
= (u64
) slave
| slave_addr
;
628 out_param
= (u64
) dev
->caps
.function
| master_addr
;
630 in_param
= (u64
) dev
->caps
.function
| master_addr
;
631 out_param
= (u64
) slave
| slave_addr
;
634 return mlx4_cmd_imm(dev
, in_param
, &out_param
, size
, 0,
636 MLX4_CMD_TIME_CLASS_A
, MLX4_CMD_NATIVE
);
639 static int query_pkey_block(struct mlx4_dev
*dev
, u8 port
, u16 index
, u16
*pkey
,
640 struct mlx4_cmd_mailbox
*inbox
,
641 struct mlx4_cmd_mailbox
*outbox
)
643 struct ib_smp
*in_mad
= (struct ib_smp
*)(inbox
->buf
);
644 struct ib_smp
*out_mad
= (struct ib_smp
*)(outbox
->buf
);
651 in_mad
->attr_mod
= cpu_to_be32(index
/ 32);
653 err
= mlx4_cmd_box(dev
, inbox
->dma
, outbox
->dma
, port
, 3,
654 MLX4_CMD_MAD_IFC
, MLX4_CMD_TIME_CLASS_C
,
659 for (i
= 0; i
< 32; ++i
)
660 pkey
[i
] = be16_to_cpu(((__be16
*) out_mad
->data
)[i
]);
665 static int get_full_pkey_table(struct mlx4_dev
*dev
, u8 port
, u16
*table
,
666 struct mlx4_cmd_mailbox
*inbox
,
667 struct mlx4_cmd_mailbox
*outbox
)
672 for (i
= 0; i
< dev
->caps
.pkey_table_len
[port
]; i
+= 32) {
673 err
= query_pkey_block(dev
, port
, i
, table
+ i
, inbox
, outbox
);
680 #define PORT_CAPABILITY_LOCATION_IN_SMP 20
681 #define PORT_STATE_OFFSET 32
683 static enum ib_port_state
vf_port_state(struct mlx4_dev
*dev
, int port
, int vf
)
685 if (mlx4_get_slave_port_state(dev
, vf
, port
) == SLAVE_PORT_UP
)
686 return IB_PORT_ACTIVE
;
691 static int mlx4_MAD_IFC_wrapper(struct mlx4_dev
*dev
, int slave
,
692 struct mlx4_vhcr
*vhcr
,
693 struct mlx4_cmd_mailbox
*inbox
,
694 struct mlx4_cmd_mailbox
*outbox
,
695 struct mlx4_cmd_info
*cmd
)
697 struct ib_smp
*smp
= inbox
->buf
;
703 struct mlx4_priv
*priv
= mlx4_priv(dev
);
704 struct ib_smp
*outsmp
= outbox
->buf
;
705 __be16
*outtab
= (__be16
*)(outsmp
->data
);
706 __be32 slave_cap_mask
;
707 __be64 slave_node_guid
;
708 port
= vhcr
->in_modifier
;
710 if (smp
->base_version
== 1 &&
711 smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_LID_ROUTED
&&
712 smp
->class_version
== 1) {
713 if (smp
->method
== IB_MGMT_METHOD_GET
) {
714 if (smp
->attr_id
== IB_SMP_ATTR_PKEY_TABLE
) {
715 index
= be32_to_cpu(smp
->attr_mod
);
716 if (port
< 1 || port
> dev
->caps
.num_ports
)
718 table
= kcalloc(dev
->caps
.pkey_table_len
[port
], sizeof *table
, GFP_KERNEL
);
721 /* need to get the full pkey table because the paravirtualized
722 * pkeys may be scattered among several pkey blocks.
724 err
= get_full_pkey_table(dev
, port
, table
, inbox
, outbox
);
726 for (vidx
= index
* 32; vidx
< (index
+ 1) * 32; ++vidx
) {
727 pidx
= priv
->virt2phys_pkey
[slave
][port
- 1][vidx
];
728 outtab
[vidx
% 32] = cpu_to_be16(table
[pidx
]);
734 if (smp
->attr_id
== IB_SMP_ATTR_PORT_INFO
) {
735 /*get the slave specific caps:*/
737 err
= mlx4_cmd_box(dev
, inbox
->dma
, outbox
->dma
,
738 vhcr
->in_modifier
, vhcr
->op_modifier
,
739 vhcr
->op
, MLX4_CMD_TIME_CLASS_C
, MLX4_CMD_NATIVE
);
740 /* modify the response for slaves */
741 if (!err
&& slave
!= mlx4_master_func_num(dev
)) {
742 u8
*state
= outsmp
->data
+ PORT_STATE_OFFSET
;
744 *state
= (*state
& 0xf0) | vf_port_state(dev
, port
, slave
);
745 slave_cap_mask
= priv
->mfunc
.master
.slave_state
[slave
].ib_cap_mask
[port
];
746 memcpy(outsmp
->data
+ PORT_CAPABILITY_LOCATION_IN_SMP
, &slave_cap_mask
, 4);
750 if (smp
->attr_id
== IB_SMP_ATTR_GUID_INFO
) {
751 /* compute slave's gid block */
752 smp
->attr_mod
= cpu_to_be32(slave
/ 8);
754 err
= mlx4_cmd_box(dev
, inbox
->dma
, outbox
->dma
,
755 vhcr
->in_modifier
, vhcr
->op_modifier
,
756 vhcr
->op
, MLX4_CMD_TIME_CLASS_C
, MLX4_CMD_NATIVE
);
758 /* if needed, move slave gid to index 0 */
761 outsmp
->data
+ (slave
% 8) * 8, 8);
762 /* delete all other gids */
763 memset(outsmp
->data
+ 8, 0, 56);
767 if (smp
->attr_id
== IB_SMP_ATTR_NODE_INFO
) {
768 err
= mlx4_cmd_box(dev
, inbox
->dma
, outbox
->dma
,
769 vhcr
->in_modifier
, vhcr
->op_modifier
,
770 vhcr
->op
, MLX4_CMD_TIME_CLASS_C
, MLX4_CMD_NATIVE
);
772 slave_node_guid
= mlx4_get_slave_node_guid(dev
, slave
);
773 memcpy(outsmp
->data
+ 12, &slave_node_guid
, 8);
779 if (slave
!= mlx4_master_func_num(dev
) &&
780 ((smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) ||
781 (smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_LID_ROUTED
&&
782 smp
->method
== IB_MGMT_METHOD_SET
))) {
783 mlx4_err(dev
, "slave %d is trying to execute a Subnet MGMT MAD, "
784 "class 0x%x, method 0x%x for attr 0x%x. Rejecting\n",
785 slave
, smp
->method
, smp
->mgmt_class
,
786 be16_to_cpu(smp
->attr_id
));
790 return mlx4_cmd_box(dev
, inbox
->dma
, outbox
->dma
,
791 vhcr
->in_modifier
, vhcr
->op_modifier
,
792 vhcr
->op
, MLX4_CMD_TIME_CLASS_C
, MLX4_CMD_NATIVE
);
795 int mlx4_DMA_wrapper(struct mlx4_dev
*dev
, int slave
,
796 struct mlx4_vhcr
*vhcr
,
797 struct mlx4_cmd_mailbox
*inbox
,
798 struct mlx4_cmd_mailbox
*outbox
,
799 struct mlx4_cmd_info
*cmd
)
805 in_param
= cmd
->has_inbox
? (u64
) inbox
->dma
: vhcr
->in_param
;
806 out_param
= cmd
->has_outbox
? (u64
) outbox
->dma
: vhcr
->out_param
;
807 if (cmd
->encode_slave_id
) {
808 in_param
&= 0xffffffffffffff00ll
;
812 err
= __mlx4_cmd(dev
, in_param
, &out_param
, cmd
->out_is_imm
,
813 vhcr
->in_modifier
, vhcr
->op_modifier
, vhcr
->op
,
814 MLX4_CMD_TIME_CLASS_A
, MLX4_CMD_NATIVE
);
817 vhcr
->out_param
= out_param
;
822 static struct mlx4_cmd_info cmd_info
[] = {
824 .opcode
= MLX4_CMD_QUERY_FW
,
828 .encode_slave_id
= false,
830 .wrapper
= mlx4_QUERY_FW_wrapper
833 .opcode
= MLX4_CMD_QUERY_HCA
,
837 .encode_slave_id
= false,
842 .opcode
= MLX4_CMD_QUERY_DEV_CAP
,
846 .encode_slave_id
= false,
848 .wrapper
= mlx4_QUERY_DEV_CAP_wrapper
851 .opcode
= MLX4_CMD_QUERY_FUNC_CAP
,
855 .encode_slave_id
= false,
857 .wrapper
= mlx4_QUERY_FUNC_CAP_wrapper
860 .opcode
= MLX4_CMD_QUERY_ADAPTER
,
864 .encode_slave_id
= false,
869 .opcode
= MLX4_CMD_INIT_PORT
,
873 .encode_slave_id
= false,
875 .wrapper
= mlx4_INIT_PORT_wrapper
878 .opcode
= MLX4_CMD_CLOSE_PORT
,
882 .encode_slave_id
= false,
884 .wrapper
= mlx4_CLOSE_PORT_wrapper
887 .opcode
= MLX4_CMD_QUERY_PORT
,
891 .encode_slave_id
= false,
893 .wrapper
= mlx4_QUERY_PORT_wrapper
896 .opcode
= MLX4_CMD_SET_PORT
,
900 .encode_slave_id
= false,
902 .wrapper
= mlx4_SET_PORT_wrapper
905 .opcode
= MLX4_CMD_MAP_EQ
,
909 .encode_slave_id
= false,
911 .wrapper
= mlx4_MAP_EQ_wrapper
914 .opcode
= MLX4_CMD_SW2HW_EQ
,
918 .encode_slave_id
= true,
920 .wrapper
= mlx4_SW2HW_EQ_wrapper
923 .opcode
= MLX4_CMD_HW_HEALTH_CHECK
,
927 .encode_slave_id
= false,
932 .opcode
= MLX4_CMD_NOP
,
936 .encode_slave_id
= false,
941 .opcode
= MLX4_CMD_ALLOC_RES
,
945 .encode_slave_id
= false,
947 .wrapper
= mlx4_ALLOC_RES_wrapper
950 .opcode
= MLX4_CMD_FREE_RES
,
954 .encode_slave_id
= false,
956 .wrapper
= mlx4_FREE_RES_wrapper
959 .opcode
= MLX4_CMD_SW2HW_MPT
,
963 .encode_slave_id
= true,
965 .wrapper
= mlx4_SW2HW_MPT_wrapper
968 .opcode
= MLX4_CMD_QUERY_MPT
,
972 .encode_slave_id
= false,
974 .wrapper
= mlx4_QUERY_MPT_wrapper
977 .opcode
= MLX4_CMD_HW2SW_MPT
,
981 .encode_slave_id
= false,
983 .wrapper
= mlx4_HW2SW_MPT_wrapper
986 .opcode
= MLX4_CMD_READ_MTT
,
990 .encode_slave_id
= false,
995 .opcode
= MLX4_CMD_WRITE_MTT
,
999 .encode_slave_id
= false,
1001 .wrapper
= mlx4_WRITE_MTT_wrapper
1004 .opcode
= MLX4_CMD_SYNC_TPT
,
1006 .has_outbox
= false,
1007 .out_is_imm
= false,
1008 .encode_slave_id
= false,
1013 .opcode
= MLX4_CMD_HW2SW_EQ
,
1016 .out_is_imm
= false,
1017 .encode_slave_id
= true,
1019 .wrapper
= mlx4_HW2SW_EQ_wrapper
1022 .opcode
= MLX4_CMD_QUERY_EQ
,
1025 .out_is_imm
= false,
1026 .encode_slave_id
= true,
1028 .wrapper
= mlx4_QUERY_EQ_wrapper
1031 .opcode
= MLX4_CMD_SW2HW_CQ
,
1033 .has_outbox
= false,
1034 .out_is_imm
= false,
1035 .encode_slave_id
= true,
1037 .wrapper
= mlx4_SW2HW_CQ_wrapper
1040 .opcode
= MLX4_CMD_HW2SW_CQ
,
1042 .has_outbox
= false,
1043 .out_is_imm
= false,
1044 .encode_slave_id
= false,
1046 .wrapper
= mlx4_HW2SW_CQ_wrapper
1049 .opcode
= MLX4_CMD_QUERY_CQ
,
1052 .out_is_imm
= false,
1053 .encode_slave_id
= false,
1055 .wrapper
= mlx4_QUERY_CQ_wrapper
1058 .opcode
= MLX4_CMD_MODIFY_CQ
,
1060 .has_outbox
= false,
1062 .encode_slave_id
= false,
1064 .wrapper
= mlx4_MODIFY_CQ_wrapper
1067 .opcode
= MLX4_CMD_SW2HW_SRQ
,
1069 .has_outbox
= false,
1070 .out_is_imm
= false,
1071 .encode_slave_id
= true,
1073 .wrapper
= mlx4_SW2HW_SRQ_wrapper
1076 .opcode
= MLX4_CMD_HW2SW_SRQ
,
1078 .has_outbox
= false,
1079 .out_is_imm
= false,
1080 .encode_slave_id
= false,
1082 .wrapper
= mlx4_HW2SW_SRQ_wrapper
1085 .opcode
= MLX4_CMD_QUERY_SRQ
,
1088 .out_is_imm
= false,
1089 .encode_slave_id
= false,
1091 .wrapper
= mlx4_QUERY_SRQ_wrapper
1094 .opcode
= MLX4_CMD_ARM_SRQ
,
1096 .has_outbox
= false,
1097 .out_is_imm
= false,
1098 .encode_slave_id
= false,
1100 .wrapper
= mlx4_ARM_SRQ_wrapper
1103 .opcode
= MLX4_CMD_RST2INIT_QP
,
1105 .has_outbox
= false,
1106 .out_is_imm
= false,
1107 .encode_slave_id
= true,
1109 .wrapper
= mlx4_RST2INIT_QP_wrapper
1112 .opcode
= MLX4_CMD_INIT2INIT_QP
,
1114 .has_outbox
= false,
1115 .out_is_imm
= false,
1116 .encode_slave_id
= false,
1118 .wrapper
= mlx4_INIT2INIT_QP_wrapper
1121 .opcode
= MLX4_CMD_INIT2RTR_QP
,
1123 .has_outbox
= false,
1124 .out_is_imm
= false,
1125 .encode_slave_id
= false,
1127 .wrapper
= mlx4_INIT2RTR_QP_wrapper
1130 .opcode
= MLX4_CMD_RTR2RTS_QP
,
1132 .has_outbox
= false,
1133 .out_is_imm
= false,
1134 .encode_slave_id
= false,
1136 .wrapper
= mlx4_RTR2RTS_QP_wrapper
1139 .opcode
= MLX4_CMD_RTS2RTS_QP
,
1141 .has_outbox
= false,
1142 .out_is_imm
= false,
1143 .encode_slave_id
= false,
1145 .wrapper
= mlx4_RTS2RTS_QP_wrapper
1148 .opcode
= MLX4_CMD_SQERR2RTS_QP
,
1150 .has_outbox
= false,
1151 .out_is_imm
= false,
1152 .encode_slave_id
= false,
1154 .wrapper
= mlx4_SQERR2RTS_QP_wrapper
1157 .opcode
= MLX4_CMD_2ERR_QP
,
1159 .has_outbox
= false,
1160 .out_is_imm
= false,
1161 .encode_slave_id
= false,
1163 .wrapper
= mlx4_GEN_QP_wrapper
1166 .opcode
= MLX4_CMD_RTS2SQD_QP
,
1168 .has_outbox
= false,
1169 .out_is_imm
= false,
1170 .encode_slave_id
= false,
1172 .wrapper
= mlx4_GEN_QP_wrapper
1175 .opcode
= MLX4_CMD_SQD2SQD_QP
,
1177 .has_outbox
= false,
1178 .out_is_imm
= false,
1179 .encode_slave_id
= false,
1181 .wrapper
= mlx4_SQD2SQD_QP_wrapper
1184 .opcode
= MLX4_CMD_SQD2RTS_QP
,
1186 .has_outbox
= false,
1187 .out_is_imm
= false,
1188 .encode_slave_id
= false,
1190 .wrapper
= mlx4_SQD2RTS_QP_wrapper
1193 .opcode
= MLX4_CMD_2RST_QP
,
1195 .has_outbox
= false,
1196 .out_is_imm
= false,
1197 .encode_slave_id
= false,
1199 .wrapper
= mlx4_2RST_QP_wrapper
1202 .opcode
= MLX4_CMD_QUERY_QP
,
1205 .out_is_imm
= false,
1206 .encode_slave_id
= false,
1208 .wrapper
= mlx4_GEN_QP_wrapper
1211 .opcode
= MLX4_CMD_SUSPEND_QP
,
1213 .has_outbox
= false,
1214 .out_is_imm
= false,
1215 .encode_slave_id
= false,
1217 .wrapper
= mlx4_GEN_QP_wrapper
1220 .opcode
= MLX4_CMD_UNSUSPEND_QP
,
1222 .has_outbox
= false,
1223 .out_is_imm
= false,
1224 .encode_slave_id
= false,
1226 .wrapper
= mlx4_GEN_QP_wrapper
1229 .opcode
= MLX4_CMD_CONF_SPECIAL_QP
,
1231 .has_outbox
= false,
1232 .out_is_imm
= false,
1233 .encode_slave_id
= false,
1234 .verify
= NULL
, /* XXX verify: only demux can do this */
1238 .opcode
= MLX4_CMD_MAD_IFC
,
1241 .out_is_imm
= false,
1242 .encode_slave_id
= false,
1244 .wrapper
= mlx4_MAD_IFC_wrapper
1247 .opcode
= MLX4_CMD_QUERY_IF_STAT
,
1250 .out_is_imm
= false,
1251 .encode_slave_id
= false,
1253 .wrapper
= mlx4_QUERY_IF_STAT_wrapper
1255 /* Native multicast commands are not available for guests */
1257 .opcode
= MLX4_CMD_QP_ATTACH
,
1259 .has_outbox
= false,
1260 .out_is_imm
= false,
1261 .encode_slave_id
= false,
1263 .wrapper
= mlx4_QP_ATTACH_wrapper
1266 .opcode
= MLX4_CMD_PROMISC
,
1268 .has_outbox
= false,
1269 .out_is_imm
= false,
1270 .encode_slave_id
= false,
1272 .wrapper
= mlx4_PROMISC_wrapper
1274 /* Ethernet specific commands */
1276 .opcode
= MLX4_CMD_SET_VLAN_FLTR
,
1278 .has_outbox
= false,
1279 .out_is_imm
= false,
1280 .encode_slave_id
= false,
1282 .wrapper
= mlx4_SET_VLAN_FLTR_wrapper
1285 .opcode
= MLX4_CMD_SET_MCAST_FLTR
,
1287 .has_outbox
= false,
1288 .out_is_imm
= false,
1289 .encode_slave_id
= false,
1291 .wrapper
= mlx4_SET_MCAST_FLTR_wrapper
1294 .opcode
= MLX4_CMD_DUMP_ETH_STATS
,
1297 .out_is_imm
= false,
1298 .encode_slave_id
= false,
1300 .wrapper
= mlx4_DUMP_ETH_STATS_wrapper
1303 .opcode
= MLX4_CMD_INFORM_FLR_DONE
,
1305 .has_outbox
= false,
1306 .out_is_imm
= false,
1307 .encode_slave_id
= false,
1311 /* flow steering commands */
1313 .opcode
= MLX4_QP_FLOW_STEERING_ATTACH
,
1315 .has_outbox
= false,
1317 .encode_slave_id
= false,
1319 .wrapper
= mlx4_QP_FLOW_STEERING_ATTACH_wrapper
1322 .opcode
= MLX4_QP_FLOW_STEERING_DETACH
,
1324 .has_outbox
= false,
1325 .out_is_imm
= false,
1326 .encode_slave_id
= false,
1328 .wrapper
= mlx4_QP_FLOW_STEERING_DETACH_wrapper
1332 static int mlx4_master_process_vhcr(struct mlx4_dev
*dev
, int slave
,
1333 struct mlx4_vhcr_cmd
*in_vhcr
)
1335 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1336 struct mlx4_cmd_info
*cmd
= NULL
;
1337 struct mlx4_vhcr_cmd
*vhcr_cmd
= in_vhcr
? in_vhcr
: priv
->mfunc
.vhcr
;
1338 struct mlx4_vhcr
*vhcr
;
1339 struct mlx4_cmd_mailbox
*inbox
= NULL
;
1340 struct mlx4_cmd_mailbox
*outbox
= NULL
;
1347 /* Create sw representation of Virtual HCR */
1348 vhcr
= kzalloc(sizeof(struct mlx4_vhcr
), GFP_KERNEL
);
1352 /* DMA in the vHCR */
1354 ret
= mlx4_ACCESS_MEM(dev
, priv
->mfunc
.vhcr_dma
, slave
,
1355 priv
->mfunc
.master
.slave_state
[slave
].vhcr_dma
,
1356 ALIGN(sizeof(struct mlx4_vhcr_cmd
),
1357 MLX4_ACCESS_MEM_ALIGN
), 1);
1359 mlx4_err(dev
, "%s:Failed reading vhcr"
1360 "ret: 0x%x\n", __func__
, ret
);
1366 /* Fill SW VHCR fields */
1367 vhcr
->in_param
= be64_to_cpu(vhcr_cmd
->in_param
);
1368 vhcr
->out_param
= be64_to_cpu(vhcr_cmd
->out_param
);
1369 vhcr
->in_modifier
= be32_to_cpu(vhcr_cmd
->in_modifier
);
1370 vhcr
->token
= be16_to_cpu(vhcr_cmd
->token
);
1371 vhcr
->op
= be16_to_cpu(vhcr_cmd
->opcode
) & 0xfff;
1372 vhcr
->op_modifier
= (u8
) (be16_to_cpu(vhcr_cmd
->opcode
) >> 12);
1373 vhcr
->e_bit
= vhcr_cmd
->flags
& (1 << 6);
1375 /* Lookup command */
1376 for (i
= 0; i
< ARRAY_SIZE(cmd_info
); ++i
) {
1377 if (vhcr
->op
== cmd_info
[i
].opcode
) {
1383 mlx4_err(dev
, "Unknown command:0x%x accepted from slave:%d\n",
1385 vhcr_cmd
->status
= CMD_STAT_BAD_PARAM
;
1390 if (cmd
->has_inbox
) {
1391 vhcr
->in_param
&= INBOX_MASK
;
1392 inbox
= mlx4_alloc_cmd_mailbox(dev
);
1393 if (IS_ERR(inbox
)) {
1394 vhcr_cmd
->status
= CMD_STAT_BAD_SIZE
;
1399 if (mlx4_ACCESS_MEM(dev
, inbox
->dma
, slave
,
1401 MLX4_MAILBOX_SIZE
, 1)) {
1402 mlx4_err(dev
, "%s: Failed reading inbox (cmd:0x%x)\n",
1403 __func__
, cmd
->opcode
);
1404 vhcr_cmd
->status
= CMD_STAT_INTERNAL_ERR
;
1409 /* Apply permission and bound checks if applicable */
1410 if (cmd
->verify
&& cmd
->verify(dev
, slave
, vhcr
, inbox
)) {
1411 mlx4_warn(dev
, "Command:0x%x from slave: %d failed protection "
1412 "checks for resource_id:%d\n", vhcr
->op
, slave
,
1414 vhcr_cmd
->status
= CMD_STAT_BAD_OP
;
1418 /* Allocate outbox */
1419 if (cmd
->has_outbox
) {
1420 outbox
= mlx4_alloc_cmd_mailbox(dev
);
1421 if (IS_ERR(outbox
)) {
1422 vhcr_cmd
->status
= CMD_STAT_BAD_SIZE
;
1428 /* Execute the command! */
1430 err
= cmd
->wrapper(dev
, slave
, vhcr
, inbox
, outbox
,
1432 if (cmd
->out_is_imm
)
1433 vhcr_cmd
->out_param
= cpu_to_be64(vhcr
->out_param
);
1435 in_param
= cmd
->has_inbox
? (u64
) inbox
->dma
:
1437 out_param
= cmd
->has_outbox
? (u64
) outbox
->dma
:
1439 err
= __mlx4_cmd(dev
, in_param
, &out_param
,
1440 cmd
->out_is_imm
, vhcr
->in_modifier
,
1441 vhcr
->op_modifier
, vhcr
->op
,
1442 MLX4_CMD_TIME_CLASS_A
,
1445 if (cmd
->out_is_imm
) {
1446 vhcr
->out_param
= out_param
;
1447 vhcr_cmd
->out_param
= cpu_to_be64(vhcr
->out_param
);
1452 mlx4_warn(dev
, "vhcr command:0x%x slave:%d failed with"
1453 " error:%d, status %d\n",
1454 vhcr
->op
, slave
, vhcr
->errno
, err
);
1455 vhcr_cmd
->status
= mlx4_errno_to_status(err
);
1460 /* Write outbox if command completed successfully */
1461 if (cmd
->has_outbox
&& !vhcr_cmd
->status
) {
1462 ret
= mlx4_ACCESS_MEM(dev
, outbox
->dma
, slave
,
1464 MLX4_MAILBOX_SIZE
, MLX4_CMD_WRAPPED
);
1466 /* If we failed to write back the outbox after the
1467 *command was successfully executed, we must fail this
1468 * slave, as it is now in undefined state */
1469 mlx4_err(dev
, "%s:Failed writing outbox\n", __func__
);
1475 /* DMA back vhcr result */
1477 ret
= mlx4_ACCESS_MEM(dev
, priv
->mfunc
.vhcr_dma
, slave
,
1478 priv
->mfunc
.master
.slave_state
[slave
].vhcr_dma
,
1479 ALIGN(sizeof(struct mlx4_vhcr
),
1480 MLX4_ACCESS_MEM_ALIGN
),
1483 mlx4_err(dev
, "%s:Failed writing vhcr result\n",
1485 else if (vhcr
->e_bit
&&
1486 mlx4_GEN_EQE(dev
, slave
, &priv
->mfunc
.master
.cmd_eqe
))
1487 mlx4_warn(dev
, "Failed to generate command completion "
1488 "eqe for slave %d\n", slave
);
1493 mlx4_free_cmd_mailbox(dev
, inbox
);
1494 mlx4_free_cmd_mailbox(dev
, outbox
);
1498 static int mlx4_master_activate_admin_state(struct mlx4_priv
*priv
, int slave
)
1501 struct mlx4_vport_state
*vp_admin
;
1502 struct mlx4_vport_oper_state
*vp_oper
;
1504 for (port
= 1; port
<= MLX4_MAX_PORTS
; port
++) {
1505 vp_oper
= &priv
->mfunc
.master
.vf_oper
[slave
].vport
[port
];
1506 vp_admin
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
1507 vp_oper
->state
= *vp_admin
;
1508 if (MLX4_VGT
!= vp_admin
->default_vlan
) {
1509 err
= __mlx4_register_vlan(&priv
->dev
, port
,
1510 vp_admin
->default_vlan
, &(vp_oper
->vlan_idx
));
1512 vp_oper
->vlan_idx
= NO_INDX
;
1513 mlx4_warn((&priv
->dev
),
1514 "No vlan resorces slave %d, port %d\n",
1518 mlx4_dbg((&(priv
->dev
)), "alloc vlan %d idx %d slave %d port %d\n",
1519 (int)(vp_oper
->state
.default_vlan
),
1520 vp_oper
->vlan_idx
, slave
, port
);
1522 if (vp_admin
->spoofchk
) {
1523 vp_oper
->mac_idx
= __mlx4_register_mac(&priv
->dev
,
1526 if (0 > vp_oper
->mac_idx
) {
1527 err
= vp_oper
->mac_idx
;
1528 vp_oper
->mac_idx
= NO_INDX
;
1529 mlx4_warn((&priv
->dev
),
1530 "No mac resorces slave %d, port %d\n",
1534 mlx4_dbg((&(priv
->dev
)), "alloc mac %llx idx %d slave %d port %d\n",
1535 vp_oper
->state
.mac
, vp_oper
->mac_idx
, slave
, port
);
1541 static void mlx4_master_deactivate_admin_state(struct mlx4_priv
*priv
, int slave
)
1544 struct mlx4_vport_oper_state
*vp_oper
;
1546 for (port
= 1; port
<= MLX4_MAX_PORTS
; port
++) {
1547 vp_oper
= &priv
->mfunc
.master
.vf_oper
[slave
].vport
[port
];
1548 if (NO_INDX
!= vp_oper
->vlan_idx
) {
1549 __mlx4_unregister_vlan(&priv
->dev
,
1550 port
, vp_oper
->vlan_idx
);
1551 vp_oper
->vlan_idx
= NO_INDX
;
1553 if (NO_INDX
!= vp_oper
->mac_idx
) {
1554 __mlx4_unregister_mac(&priv
->dev
, port
, vp_oper
->mac_idx
);
1555 vp_oper
->mac_idx
= NO_INDX
;
1561 static void mlx4_master_do_cmd(struct mlx4_dev
*dev
, int slave
, u8 cmd
,
1562 u16 param
, u8 toggle
)
1564 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1565 struct mlx4_slave_state
*slave_state
= priv
->mfunc
.master
.slave_state
;
1567 u8 is_going_down
= 0;
1569 unsigned long flags
;
1571 slave_state
[slave
].comm_toggle
^= 1;
1572 reply
= (u32
) slave_state
[slave
].comm_toggle
<< 31;
1573 if (toggle
!= slave_state
[slave
].comm_toggle
) {
1574 mlx4_warn(dev
, "Incorrect toggle %d from slave %d. *** MASTER"
1575 "STATE COMPROMISIED ***\n", toggle
, slave
);
1578 if (cmd
== MLX4_COMM_CMD_RESET
) {
1579 mlx4_warn(dev
, "Received reset from slave:%d\n", slave
);
1580 slave_state
[slave
].active
= false;
1581 mlx4_master_deactivate_admin_state(priv
, slave
);
1582 for (i
= 0; i
< MLX4_EVENT_TYPES_NUM
; ++i
) {
1583 slave_state
[slave
].event_eq
[i
].eqn
= -1;
1584 slave_state
[slave
].event_eq
[i
].token
= 0;
1586 /*check if we are in the middle of FLR process,
1587 if so return "retry" status to the slave*/
1588 if (MLX4_COMM_CMD_FLR
== slave_state
[slave
].last_cmd
)
1589 goto inform_slave_state
;
1591 mlx4_dispatch_event(dev
, MLX4_DEV_EVENT_SLAVE_SHUTDOWN
, slave
);
1593 /* write the version in the event field */
1594 reply
|= mlx4_comm_get_version();
1598 /*command from slave in the middle of FLR*/
1599 if (cmd
!= MLX4_COMM_CMD_RESET
&&
1600 MLX4_COMM_CMD_FLR
== slave_state
[slave
].last_cmd
) {
1601 mlx4_warn(dev
, "slave:%d is Trying to run cmd(0x%x) "
1602 "in the middle of FLR\n", slave
, cmd
);
1607 case MLX4_COMM_CMD_VHCR0
:
1608 if (slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_RESET
)
1610 slave_state
[slave
].vhcr_dma
= ((u64
) param
) << 48;
1611 priv
->mfunc
.master
.slave_state
[slave
].cookie
= 0;
1612 mutex_init(&priv
->mfunc
.master
.gen_eqe_mutex
[slave
]);
1614 case MLX4_COMM_CMD_VHCR1
:
1615 if (slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_VHCR0
)
1617 slave_state
[slave
].vhcr_dma
|= ((u64
) param
) << 32;
1619 case MLX4_COMM_CMD_VHCR2
:
1620 if (slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_VHCR1
)
1622 slave_state
[slave
].vhcr_dma
|= ((u64
) param
) << 16;
1624 case MLX4_COMM_CMD_VHCR_EN
:
1625 if (slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_VHCR2
)
1627 slave_state
[slave
].vhcr_dma
|= param
;
1628 if (mlx4_master_activate_admin_state(priv
, slave
))
1630 slave_state
[slave
].active
= true;
1631 mlx4_dispatch_event(dev
, MLX4_DEV_EVENT_SLAVE_INIT
, slave
);
1633 case MLX4_COMM_CMD_VHCR_POST
:
1634 if ((slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_VHCR_EN
) &&
1635 (slave_state
[slave
].last_cmd
!= MLX4_COMM_CMD_VHCR_POST
))
1638 mutex_lock(&priv
->cmd
.slave_cmd_mutex
);
1639 if (mlx4_master_process_vhcr(dev
, slave
, NULL
)) {
1640 mlx4_err(dev
, "Failed processing vhcr for slave:%d,"
1641 " resetting slave.\n", slave
);
1642 mutex_unlock(&priv
->cmd
.slave_cmd_mutex
);
1645 mutex_unlock(&priv
->cmd
.slave_cmd_mutex
);
1648 mlx4_warn(dev
, "Bad comm cmd:%d from slave:%d\n", cmd
, slave
);
1651 spin_lock_irqsave(&priv
->mfunc
.master
.slave_state_lock
, flags
);
1652 if (!slave_state
[slave
].is_slave_going_down
)
1653 slave_state
[slave
].last_cmd
= cmd
;
1656 spin_unlock_irqrestore(&priv
->mfunc
.master
.slave_state_lock
, flags
);
1657 if (is_going_down
) {
1658 mlx4_warn(dev
, "Slave is going down aborting command(%d)"
1659 " executing from slave:%d\n",
1663 __raw_writel((__force u32
) cpu_to_be32(reply
),
1664 &priv
->mfunc
.comm
[slave
].slave_read
);
1670 /* cleanup any slave resources */
1671 mlx4_delete_all_resources_for_slave(dev
, slave
);
1672 spin_lock_irqsave(&priv
->mfunc
.master
.slave_state_lock
, flags
);
1673 if (!slave_state
[slave
].is_slave_going_down
)
1674 slave_state
[slave
].last_cmd
= MLX4_COMM_CMD_RESET
;
1675 spin_unlock_irqrestore(&priv
->mfunc
.master
.slave_state_lock
, flags
);
1676 /*with slave in the middle of flr, no need to clean resources again.*/
1678 memset(&slave_state
[slave
].event_eq
, 0,
1679 sizeof(struct mlx4_slave_event_eq_info
));
1680 __raw_writel((__force u32
) cpu_to_be32(reply
),
1681 &priv
->mfunc
.comm
[slave
].slave_read
);
1685 /* master command processing */
1686 void mlx4_master_comm_channel(struct work_struct
*work
)
1688 struct mlx4_mfunc_master_ctx
*master
=
1690 struct mlx4_mfunc_master_ctx
,
1692 struct mlx4_mfunc
*mfunc
=
1693 container_of(master
, struct mlx4_mfunc
, master
);
1694 struct mlx4_priv
*priv
=
1695 container_of(mfunc
, struct mlx4_priv
, mfunc
);
1696 struct mlx4_dev
*dev
= &priv
->dev
;
1706 bit_vec
= master
->comm_arm_bit_vector
;
1707 for (i
= 0; i
< COMM_CHANNEL_BIT_ARRAY_SIZE
; i
++) {
1708 vec
= be32_to_cpu(bit_vec
[i
]);
1709 for (j
= 0; j
< 32; j
++) {
1710 if (!(vec
& (1 << j
)))
1713 slave
= (i
* 32) + j
;
1714 comm_cmd
= swab32(readl(
1715 &mfunc
->comm
[slave
].slave_write
));
1716 slt
= swab32(readl(&mfunc
->comm
[slave
].slave_read
))
1718 toggle
= comm_cmd
>> 31;
1719 if (toggle
!= slt
) {
1720 if (master
->slave_state
[slave
].comm_toggle
1722 printk(KERN_INFO
"slave %d out of sync."
1723 " read toggle %d, state toggle %d. "
1724 "Resynching.\n", slave
, slt
,
1725 master
->slave_state
[slave
].comm_toggle
);
1726 master
->slave_state
[slave
].comm_toggle
=
1729 mlx4_master_do_cmd(dev
, slave
,
1730 comm_cmd
>> 16 & 0xff,
1731 comm_cmd
& 0xffff, toggle
);
1737 if (reported
&& reported
!= served
)
1738 mlx4_warn(dev
, "Got command event with bitmask from %d slaves"
1739 " but %d were served\n",
1742 if (mlx4_ARM_COMM_CHANNEL(dev
))
1743 mlx4_warn(dev
, "Failed to arm comm channel events\n");
1746 static int sync_toggles(struct mlx4_dev
*dev
)
1748 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1753 wr_toggle
= swab32(readl(&priv
->mfunc
.comm
->slave_write
)) >> 31;
1754 end
= jiffies
+ msecs_to_jiffies(5000);
1756 while (time_before(jiffies
, end
)) {
1757 rd_toggle
= swab32(readl(&priv
->mfunc
.comm
->slave_read
)) >> 31;
1758 if (rd_toggle
== wr_toggle
) {
1759 priv
->cmd
.comm_toggle
= rd_toggle
;
1767 * we could reach here if for example the previous VM using this
1768 * function misbehaved and left the channel with unsynced state. We
1769 * should fix this here and give this VM a chance to use a properly
1772 mlx4_warn(dev
, "recovering from previously mis-behaved VM\n");
1773 __raw_writel((__force u32
) 0, &priv
->mfunc
.comm
->slave_read
);
1774 __raw_writel((__force u32
) 0, &priv
->mfunc
.comm
->slave_write
);
1775 priv
->cmd
.comm_toggle
= 0;
1780 int mlx4_multi_func_init(struct mlx4_dev
*dev
)
1782 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1783 struct mlx4_slave_state
*s_state
;
1784 int i
, j
, err
, port
;
1786 if (mlx4_is_master(dev
))
1788 ioremap(pci_resource_start(dev
->pdev
, priv
->fw
.comm_bar
) +
1789 priv
->fw
.comm_base
, MLX4_COMM_PAGESIZE
);
1792 ioremap(pci_resource_start(dev
->pdev
, 2) +
1793 MLX4_SLAVE_COMM_BASE
, MLX4_COMM_PAGESIZE
);
1794 if (!priv
->mfunc
.comm
) {
1795 mlx4_err(dev
, "Couldn't map communication vector.\n");
1799 if (mlx4_is_master(dev
)) {
1800 priv
->mfunc
.master
.slave_state
=
1801 kzalloc(dev
->num_slaves
*
1802 sizeof(struct mlx4_slave_state
), GFP_KERNEL
);
1803 if (!priv
->mfunc
.master
.slave_state
)
1806 priv
->mfunc
.master
.vf_admin
=
1807 kzalloc(dev
->num_slaves
*
1808 sizeof(struct mlx4_vf_admin_state
), GFP_KERNEL
);
1809 if (!priv
->mfunc
.master
.vf_admin
)
1810 goto err_comm_admin
;
1812 priv
->mfunc
.master
.vf_oper
=
1813 kzalloc(dev
->num_slaves
*
1814 sizeof(struct mlx4_vf_oper_state
), GFP_KERNEL
);
1815 if (!priv
->mfunc
.master
.vf_oper
)
1818 for (i
= 0; i
< dev
->num_slaves
; ++i
) {
1819 s_state
= &priv
->mfunc
.master
.slave_state
[i
];
1820 s_state
->last_cmd
= MLX4_COMM_CMD_RESET
;
1821 for (j
= 0; j
< MLX4_EVENT_TYPES_NUM
; ++j
)
1822 s_state
->event_eq
[j
].eqn
= -1;
1823 __raw_writel((__force u32
) 0,
1824 &priv
->mfunc
.comm
[i
].slave_write
);
1825 __raw_writel((__force u32
) 0,
1826 &priv
->mfunc
.comm
[i
].slave_read
);
1828 for (port
= 1; port
<= MLX4_MAX_PORTS
; port
++) {
1829 s_state
->vlan_filter
[port
] =
1830 kzalloc(sizeof(struct mlx4_vlan_fltr
),
1832 if (!s_state
->vlan_filter
[port
]) {
1834 kfree(s_state
->vlan_filter
[port
]);
1837 INIT_LIST_HEAD(&s_state
->mcast_filters
[port
]);
1838 priv
->mfunc
.master
.vf_admin
[i
].vport
[port
].default_vlan
= MLX4_VGT
;
1839 priv
->mfunc
.master
.vf_oper
[i
].vport
[port
].state
.default_vlan
= MLX4_VGT
;
1840 priv
->mfunc
.master
.vf_oper
[i
].vport
[port
].vlan_idx
= NO_INDX
;
1841 priv
->mfunc
.master
.vf_oper
[i
].vport
[port
].mac_idx
= NO_INDX
;
1843 spin_lock_init(&s_state
->lock
);
1846 memset(&priv
->mfunc
.master
.cmd_eqe
, 0, dev
->caps
.eqe_size
);
1847 priv
->mfunc
.master
.cmd_eqe
.type
= MLX4_EVENT_TYPE_CMD
;
1848 INIT_WORK(&priv
->mfunc
.master
.comm_work
,
1849 mlx4_master_comm_channel
);
1850 INIT_WORK(&priv
->mfunc
.master
.slave_event_work
,
1851 mlx4_gen_slave_eqe
);
1852 INIT_WORK(&priv
->mfunc
.master
.slave_flr_event_work
,
1853 mlx4_master_handle_slave_flr
);
1854 spin_lock_init(&priv
->mfunc
.master
.slave_state_lock
);
1855 spin_lock_init(&priv
->mfunc
.master
.slave_eq
.event_lock
);
1856 priv
->mfunc
.master
.comm_wq
=
1857 create_singlethread_workqueue("mlx4_comm");
1858 if (!priv
->mfunc
.master
.comm_wq
)
1861 if (mlx4_init_resource_tracker(dev
))
1864 err
= mlx4_ARM_COMM_CHANNEL(dev
);
1866 mlx4_err(dev
, " Failed to arm comm channel eq: %x\n",
1872 err
= sync_toggles(dev
);
1874 mlx4_err(dev
, "Couldn't sync toggles\n");
1881 mlx4_free_resource_tracker(dev
, RES_TR_FREE_ALL
);
1883 flush_workqueue(priv
->mfunc
.master
.comm_wq
);
1884 destroy_workqueue(priv
->mfunc
.master
.comm_wq
);
1887 for (port
= 1; port
<= MLX4_MAX_PORTS
; port
++)
1888 kfree(priv
->mfunc
.master
.slave_state
[i
].vlan_filter
[port
]);
1890 kfree(priv
->mfunc
.master
.vf_oper
);
1892 kfree(priv
->mfunc
.master
.vf_admin
);
1894 kfree(priv
->mfunc
.master
.slave_state
);
1896 iounmap(priv
->mfunc
.comm
);
1898 dma_free_coherent(&(dev
->pdev
->dev
), PAGE_SIZE
,
1900 priv
->mfunc
.vhcr_dma
);
1901 priv
->mfunc
.vhcr
= NULL
;
1905 int mlx4_cmd_init(struct mlx4_dev
*dev
)
1907 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1909 mutex_init(&priv
->cmd
.hcr_mutex
);
1910 mutex_init(&priv
->cmd
.slave_cmd_mutex
);
1911 sema_init(&priv
->cmd
.poll_sem
, 1);
1912 priv
->cmd
.use_events
= 0;
1913 priv
->cmd
.toggle
= 1;
1915 priv
->cmd
.hcr
= NULL
;
1916 priv
->mfunc
.vhcr
= NULL
;
1918 if (!mlx4_is_slave(dev
)) {
1919 priv
->cmd
.hcr
= ioremap(pci_resource_start(dev
->pdev
, 0) +
1920 MLX4_HCR_BASE
, MLX4_HCR_SIZE
);
1921 if (!priv
->cmd
.hcr
) {
1922 mlx4_err(dev
, "Couldn't map command register.\n");
1927 if (mlx4_is_mfunc(dev
)) {
1928 priv
->mfunc
.vhcr
= dma_alloc_coherent(&(dev
->pdev
->dev
), PAGE_SIZE
,
1929 &priv
->mfunc
.vhcr_dma
,
1931 if (!priv
->mfunc
.vhcr
)
1935 priv
->cmd
.pool
= pci_pool_create("mlx4_cmd", dev
->pdev
,
1937 MLX4_MAILBOX_SIZE
, 0);
1938 if (!priv
->cmd
.pool
)
1944 if (mlx4_is_mfunc(dev
))
1945 dma_free_coherent(&(dev
->pdev
->dev
), PAGE_SIZE
,
1946 priv
->mfunc
.vhcr
, priv
->mfunc
.vhcr_dma
);
1947 priv
->mfunc
.vhcr
= NULL
;
1950 if (!mlx4_is_slave(dev
))
1951 iounmap(priv
->cmd
.hcr
);
1955 void mlx4_multi_func_cleanup(struct mlx4_dev
*dev
)
1957 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1960 if (mlx4_is_master(dev
)) {
1961 flush_workqueue(priv
->mfunc
.master
.comm_wq
);
1962 destroy_workqueue(priv
->mfunc
.master
.comm_wq
);
1963 for (i
= 0; i
< dev
->num_slaves
; i
++) {
1964 for (port
= 1; port
<= MLX4_MAX_PORTS
; port
++)
1965 kfree(priv
->mfunc
.master
.slave_state
[i
].vlan_filter
[port
]);
1967 kfree(priv
->mfunc
.master
.slave_state
);
1968 kfree(priv
->mfunc
.master
.vf_admin
);
1969 kfree(priv
->mfunc
.master
.vf_oper
);
1972 iounmap(priv
->mfunc
.comm
);
1975 void mlx4_cmd_cleanup(struct mlx4_dev
*dev
)
1977 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1979 pci_pool_destroy(priv
->cmd
.pool
);
1981 if (!mlx4_is_slave(dev
))
1982 iounmap(priv
->cmd
.hcr
);
1983 if (mlx4_is_mfunc(dev
))
1984 dma_free_coherent(&(dev
->pdev
->dev
), PAGE_SIZE
,
1985 priv
->mfunc
.vhcr
, priv
->mfunc
.vhcr_dma
);
1986 priv
->mfunc
.vhcr
= NULL
;
1990 * Switch to using events to issue FW commands (can only be called
1991 * after event queue for command events has been initialized).
1993 int mlx4_cmd_use_events(struct mlx4_dev
*dev
)
1995 struct mlx4_priv
*priv
= mlx4_priv(dev
);
1999 priv
->cmd
.context
= kmalloc(priv
->cmd
.max_cmds
*
2000 sizeof (struct mlx4_cmd_context
),
2002 if (!priv
->cmd
.context
)
2005 for (i
= 0; i
< priv
->cmd
.max_cmds
; ++i
) {
2006 priv
->cmd
.context
[i
].token
= i
;
2007 priv
->cmd
.context
[i
].next
= i
+ 1;
2010 priv
->cmd
.context
[priv
->cmd
.max_cmds
- 1].next
= -1;
2011 priv
->cmd
.free_head
= 0;
2013 sema_init(&priv
->cmd
.event_sem
, priv
->cmd
.max_cmds
);
2014 spin_lock_init(&priv
->cmd
.context_lock
);
2016 for (priv
->cmd
.token_mask
= 1;
2017 priv
->cmd
.token_mask
< priv
->cmd
.max_cmds
;
2018 priv
->cmd
.token_mask
<<= 1)
2020 --priv
->cmd
.token_mask
;
2022 down(&priv
->cmd
.poll_sem
);
2023 priv
->cmd
.use_events
= 1;
2029 * Switch back to polling (used when shutting down the device)
2031 void mlx4_cmd_use_polling(struct mlx4_dev
*dev
)
2033 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2036 priv
->cmd
.use_events
= 0;
2038 for (i
= 0; i
< priv
->cmd
.max_cmds
; ++i
)
2039 down(&priv
->cmd
.event_sem
);
2041 kfree(priv
->cmd
.context
);
2043 up(&priv
->cmd
.poll_sem
);
2046 struct mlx4_cmd_mailbox
*mlx4_alloc_cmd_mailbox(struct mlx4_dev
*dev
)
2048 struct mlx4_cmd_mailbox
*mailbox
;
2050 mailbox
= kmalloc(sizeof *mailbox
, GFP_KERNEL
);
2052 return ERR_PTR(-ENOMEM
);
2054 mailbox
->buf
= pci_pool_alloc(mlx4_priv(dev
)->cmd
.pool
, GFP_KERNEL
,
2056 if (!mailbox
->buf
) {
2058 return ERR_PTR(-ENOMEM
);
2063 EXPORT_SYMBOL_GPL(mlx4_alloc_cmd_mailbox
);
2065 void mlx4_free_cmd_mailbox(struct mlx4_dev
*dev
,
2066 struct mlx4_cmd_mailbox
*mailbox
)
2071 pci_pool_free(mlx4_priv(dev
)->cmd
.pool
, mailbox
->buf
, mailbox
->dma
);
2074 EXPORT_SYMBOL_GPL(mlx4_free_cmd_mailbox
);
2076 u32
mlx4_comm_get_version(void)
2078 return ((u32
) CMD_CHAN_IF_REV
<< 8) | (u32
) CMD_CHAN_VER
;
2081 static int mlx4_get_slave_indx(struct mlx4_dev
*dev
, int vf
)
2083 if ((vf
< 0) || (vf
>= dev
->num_vfs
)) {
2084 mlx4_err(dev
, "Bad vf number:%d (number of activated vf: %d)\n", vf
, dev
->num_vfs
);
2091 int mlx4_set_vf_mac(struct mlx4_dev
*dev
, int port
, int vf
, u64 mac
)
2093 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2094 struct mlx4_vport_state
*s_info
;
2097 if (!mlx4_is_master(dev
))
2098 return -EPROTONOSUPPORT
;
2100 slave
= mlx4_get_slave_indx(dev
, vf
);
2104 s_info
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
2106 mlx4_info(dev
, "default mac on vf %d port %d to %llX will take afect only after vf restart\n",
2107 vf
, port
, s_info
->mac
);
2110 EXPORT_SYMBOL_GPL(mlx4_set_vf_mac
);
2112 int mlx4_set_vf_vlan(struct mlx4_dev
*dev
, int port
, int vf
, u16 vlan
, u8 qos
)
2114 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2115 struct mlx4_vport_state
*s_info
;
2118 if ((!mlx4_is_master(dev
)) ||
2119 !(dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_VLAN_CONTROL
))
2120 return -EPROTONOSUPPORT
;
2122 if ((vlan
> 4095) || (qos
> 7))
2125 slave
= mlx4_get_slave_indx(dev
, vf
);
2129 s_info
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
2130 if ((0 == vlan
) && (0 == qos
))
2131 s_info
->default_vlan
= MLX4_VGT
;
2133 s_info
->default_vlan
= vlan
;
2134 s_info
->default_qos
= qos
;
2137 EXPORT_SYMBOL_GPL(mlx4_set_vf_vlan
);
2139 int mlx4_set_vf_spoofchk(struct mlx4_dev
*dev
, int port
, int vf
, bool setting
)
2141 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2142 struct mlx4_vport_state
*s_info
;
2145 if ((!mlx4_is_master(dev
)) ||
2146 !(dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_FSM
))
2147 return -EPROTONOSUPPORT
;
2149 slave
= mlx4_get_slave_indx(dev
, vf
);
2153 s_info
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
2154 s_info
->spoofchk
= setting
;
2158 EXPORT_SYMBOL_GPL(mlx4_set_vf_spoofchk
);
2160 int mlx4_get_vf_config(struct mlx4_dev
*dev
, int port
, int vf
, struct ifla_vf_info
*ivf
)
2162 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2163 struct mlx4_vport_state
*s_info
;
2166 if (!mlx4_is_master(dev
))
2167 return -EPROTONOSUPPORT
;
2169 slave
= mlx4_get_slave_indx(dev
, vf
);
2173 s_info
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
2176 /* need to convert it to a func */
2177 ivf
->mac
[0] = ((s_info
->mac
>> (5*8)) & 0xff);
2178 ivf
->mac
[1] = ((s_info
->mac
>> (4*8)) & 0xff);
2179 ivf
->mac
[2] = ((s_info
->mac
>> (3*8)) & 0xff);
2180 ivf
->mac
[3] = ((s_info
->mac
>> (2*8)) & 0xff);
2181 ivf
->mac
[4] = ((s_info
->mac
>> (1*8)) & 0xff);
2182 ivf
->mac
[5] = ((s_info
->mac
) & 0xff);
2184 ivf
->vlan
= s_info
->default_vlan
;
2185 ivf
->qos
= s_info
->default_qos
;
2186 ivf
->tx_rate
= s_info
->tx_rate
;
2187 ivf
->spoofchk
= s_info
->spoofchk
;
2188 ivf
->linkstate
= s_info
->link_state
;
2192 EXPORT_SYMBOL_GPL(mlx4_get_vf_config
);
2194 int mlx4_set_vf_link_state(struct mlx4_dev
*dev
, int port
, int vf
, int link_state
)
2196 struct mlx4_priv
*priv
= mlx4_priv(dev
);
2197 struct mlx4_vport_state
*s_info
;
2198 struct mlx4_vport_oper_state
*vp_oper
;
2202 slave
= mlx4_get_slave_indx(dev
, vf
);
2206 switch (link_state
) {
2207 case IFLA_VF_LINK_STATE_AUTO
:
2208 /* get current link state */
2209 if (!priv
->sense
.do_sense_port
[port
])
2210 link_stat_event
= MLX4_PORT_CHANGE_SUBTYPE_ACTIVE
;
2212 link_stat_event
= MLX4_PORT_CHANGE_SUBTYPE_DOWN
;
2215 case IFLA_VF_LINK_STATE_ENABLE
:
2216 link_stat_event
= MLX4_PORT_CHANGE_SUBTYPE_ACTIVE
;
2219 case IFLA_VF_LINK_STATE_DISABLE
:
2220 link_stat_event
= MLX4_PORT_CHANGE_SUBTYPE_DOWN
;
2224 mlx4_warn(dev
, "unknown value for link_state %02x on slave %d port %d\n",
2225 link_state
, slave
, port
);
2228 /* update the admin & oper state on the link state */
2229 s_info
= &priv
->mfunc
.master
.vf_admin
[slave
].vport
[port
];
2230 vp_oper
= &priv
->mfunc
.master
.vf_oper
[slave
].vport
[port
];
2231 s_info
->link_state
= link_state
;
2232 vp_oper
->state
.link_state
= link_state
;
2235 mlx4_gen_port_state_change_eqe(dev
, slave
, port
, link_stat_event
);
2238 EXPORT_SYMBOL_GPL(mlx4_set_vf_link_state
);