doc: whitespace changes in licenses
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe_pf.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <errno.h>
36 #include <stdint.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <stdarg.h>
40 #include <inttypes.h>
41
42 #include <rte_interrupts.h>
43 #include <rte_log.h>
44 #include <rte_debug.h>
45 #include <rte_eal.h>
46 #include <rte_ether.h>
47 #include <rte_ethdev.h>
48 #include <rte_memcpy.h>
49 #include <rte_malloc.h>
50 #include <rte_random.h>
51
52 #include "ixgbe/ixgbe_common.h"
53 #include "ixgbe_ethdev.h"
54
55 #define IXGBE_MAX_VFTA     (128)
56
57 static inline 
58 void eth_random_addr(uint8_t *addr)
59 {
60         uint64_t rand = rte_rand();
61         uint8_t *p = (uint8_t*)&rand;
62
63         rte_memcpy(addr, p, ETHER_ADDR_LEN);
64         addr[0] &= 0xfe;        /* clear multicast bit */
65         addr[0] |= 0x02;        /* set local assignment bit (IEEE802) */
66 }
67
68 static inline uint16_t
69 dev_num_vf(struct rte_eth_dev *eth_dev)
70 {
71         return eth_dev->pci_dev->max_vfs;
72 }
73
74 static inline 
75 int ixgbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
76 {
77         unsigned char vf_mac_addr[ETHER_ADDR_LEN];
78         struct ixgbe_vf_info *vfinfo = 
79                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
80         uint16_t vfn;
81
82         for (vfn = 0; vfn < vf_num; vfn++) {
83                 eth_random_addr(vf_mac_addr);
84                 /* keep the random address as default */
85                 memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 
86                            ETHER_ADDR_LEN);
87         }
88
89         return 0;
90 }
91
92 static inline int
93 ixgbe_mb_intr_setup(struct rte_eth_dev *dev)
94 {
95         struct ixgbe_interrupt *intr =
96                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
97
98         intr->mask |= IXGBE_EICR_MAILBOX;
99
100         return 0;
101 }
102
103 void ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
104 {
105         struct ixgbe_vf_info **vfinfo = 
106                 IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
107         struct ixgbe_hw *hw = 
108                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
109         uint16_t vf_num;
110         uint8_t nb_queue;
111
112         PMD_INIT_FUNC_TRACE();
113
114         RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
115         if (0 == (vf_num = dev_num_vf(eth_dev)))
116                 return;
117
118         *vfinfo = rte_zmalloc("vf_info", sizeof(struct ixgbe_vf_info) * vf_num, 0);
119         if (*vfinfo == NULL)
120                 rte_panic("Cannot allocate memory for private VF data\n");
121
122         if (vf_num >= ETH_32_POOLS) {
123                 nb_queue = 2;
124                 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_64_POOLS;
125         } else if (vf_num >= ETH_16_POOLS) {
126                 nb_queue = 4;
127                 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_32_POOLS;
128         } else {
129                 nb_queue = 8;
130                 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_16_POOLS;
131         }
132
133         RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
134         RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
135         RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = (uint16_t)(vf_num * nb_queue);
136
137         ixgbe_vf_perm_addr_gen(eth_dev, vf_num);
138
139         /* init_mailbox_params */
140         hw->mbx.ops.init_params(hw);
141
142         /* set mb interrupt mask */
143         ixgbe_mb_intr_setup(eth_dev);
144
145         return;
146 }
147
148 int ixgbe_pf_host_configure(struct rte_eth_dev *eth_dev)
149 {
150         uint32_t vtctl, fcrth;
151         uint32_t vfre_slot, vfre_offset;
152         uint16_t vf_num;
153         const uint8_t VFRE_SHIFT = 5;  /* VFRE 32 bits per slot */
154         const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
155         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
156         uint32_t gpie, gcr_ext;
157         uint32_t vlanctrl;
158         int i;
159
160         if (0 == (vf_num = dev_num_vf(eth_dev)))
161                 return -1;
162
163         /* enable VMDq and set the default pool for PF */
164         vtctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
165         vtctl |= IXGBE_VMD_CTL_VMDQ_EN;
166         vtctl &= ~IXGBE_VT_CTL_POOL_MASK;
167         vtctl |= RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx 
168                 << IXGBE_VT_CTL_POOL_SHIFT;
169         vtctl |= IXGBE_VT_CTL_REPLEN;
170         IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vtctl);
171
172         vfre_offset = vf_num & VFRE_MASK; 
173         vfre_slot = (vf_num >> VFRE_SHIFT) > 0 ? 1 : 0;
174         
175         /* Enable pools reserved to PF only */
176         IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot), (~0) << vfre_offset);
177         IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot ^ 1), vfre_slot - 1);
178         IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot), (~0) << vfre_offset);
179         IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot ^ 1), vfre_slot - 1);
180
181         /* PFDMA Tx General Switch Control Enables VMDQ loopback */
182         IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
183
184         /* clear VMDq map to perment rar 0 */
185         hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
186
187         /* clear VMDq map to scan rar 127 */
188         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(hw->mac.num_rar_entries), 0);
189         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(hw->mac.num_rar_entries), 0);
190
191         /* set VMDq map to default PF pool */
192         hw->mac.ops.set_vmdq(hw, 0, RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
193
194         /*
195          * SW msut set GCR_EXT.VT_Mode the same as GPIE.VT_Mode
196          */
197         gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
198         gcr_ext &= ~IXGBE_GCR_EXT_VT_MODE_MASK;
199         
200         gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
201         gpie &= ~IXGBE_GPIE_VTMODE_MASK;
202         gpie |= IXGBE_GPIE_MSIX_MODE;
203         
204         switch (RTE_ETH_DEV_SRIOV(eth_dev).active) {
205         case ETH_64_POOLS:
206                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
207                 gpie |= IXGBE_GPIE_VTMODE_64;
208                 break;
209         case ETH_32_POOLS:
210                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_32;
211                 gpie |= IXGBE_GPIE_VTMODE_32;
212                 break;
213         case ETH_16_POOLS:
214                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_16;
215                 gpie |= IXGBE_GPIE_VTMODE_16;
216                 break;
217         }
218
219         IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
220         IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
221
222         /* 
223          * enable vlan filtering and allow all vlan tags through 
224          */
225         vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
226         vlanctrl |= IXGBE_VLNCTRL_VFE ; /* enable vlan filters */
227         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
228
229         /* VFTA - enable all vlan filters */
230         for (i = 0; i < IXGBE_MAX_VFTA; i++) {
231                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
232         }
233         
234         /* Enable MAC Anti-Spoofing */
235         hw->mac.ops.set_mac_anti_spoofing(hw, FALSE, vf_num);
236
237         /* set flow control threshold to max to avoid tx switch hang */ 
238         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
239                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
240                 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
241                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
242         }
243
244         return 0;
245 }
246
247 static void 
248 set_rx_mode(struct rte_eth_dev *dev)
249 {
250         struct rte_eth_dev_data *dev_data = 
251                 (struct rte_eth_dev_data*)dev->data->dev_private;
252         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
253         u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
254         uint16_t vfn = dev_num_vf(dev);
255
256         /* Check for Promiscuous and All Multicast modes */
257         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
258
259         /* set all bits that we expect to always be set */
260         fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
261         fctrl |= IXGBE_FCTRL_BAM;
262
263         /* clear the bits we are changing the status of */
264         fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
265
266         if (dev_data->promiscuous) {
267                 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
268                 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
269                 /* don't hardware filter vlans in promisc mode */
270                 ixgbe_vlan_hw_filter_disable(dev);
271         } else {
272                 if (dev_data->all_multicast) {
273                         fctrl |= IXGBE_FCTRL_MPE;
274                         vmolr |= IXGBE_VMOLR_MPE;
275                 } else {
276                         vmolr |= IXGBE_VMOLR_ROMPE;
277                 }
278                 ixgbe_vlan_hw_filter_enable(dev);
279         }
280
281         if (hw->mac.type != ixgbe_mac_82598EB) {
282                 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(vfn)) &
283                          ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
284                            IXGBE_VMOLR_ROPE);
285                 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vfn), vmolr);
286         }
287
288         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
289
290         if (dev->data->dev_conf.rxmode.hw_vlan_strip)
291                 ixgbe_vlan_hw_strip_enable_all(dev);
292         else
293                 ixgbe_vlan_hw_strip_disable_all(dev);
294 }
295
296 static inline void 
297 ixgbe_vf_reset_event(struct rte_eth_dev *dev, uint16_t vf)
298 {
299         struct ixgbe_hw *hw = 
300                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
301         struct ixgbe_vf_info *vfinfo = 
302                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
303         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
304         uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
305
306         vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_ROMPE | 
307                         IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
308         IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
309
310         IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
311         
312         /* reset multicast table array for vf */
313         vfinfo[vf].num_vf_mc_hashes = 0;
314
315         /* reset rx mode */
316         set_rx_mode(dev);
317         
318         hw->mac.ops.clear_rar(hw, rar_entry);
319 }
320
321 static inline void 
322 ixgbe_vf_reset_msg(struct rte_eth_dev *dev, uint16_t vf)
323 {
324         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
325         uint32_t reg;
326         uint32_t reg_offset, vf_shift;
327         const uint8_t VFRE_SHIFT = 5;  /* VFRE 32 bits per slot */
328         const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
329
330         vf_shift = vf & VFRE_MASK;
331         reg_offset = (vf >> VFRE_SHIFT) > 0 ? 1 : 0;
332
333         /* enable transmit and receive for vf */
334         reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
335         reg |= (reg | (1 << vf_shift));
336         IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
337
338         reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
339         reg |= (reg | (1 << vf_shift));
340         IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
341
342         /* Enable counting of spoofed packets in the SSVPC register */
343         reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
344         reg |= (1 << vf_shift);
345         IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
346
347         ixgbe_vf_reset_event(dev, vf);
348 }
349
350 static int
351 ixgbe_vf_reset(struct rte_eth_dev *dev, uint16_t vf, uint32_t *msgbuf)
352 {
353         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
354         struct ixgbe_vf_info *vfinfo = 
355                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
356         unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
357         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
358         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
359
360         ixgbe_vf_reset_msg(dev, vf);
361
362         hw->mac.ops.set_rar(hw, rar_entry, vf_mac, vf, IXGBE_RAH_AV);
363
364         /* reply to reset with ack and vf mac address */
365         msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK;
366         rte_memcpy(new_mac, vf_mac, ETHER_ADDR_LEN);
367         /*
368          * Piggyback the multicast filter type so VF can compute the
369          * correct vectors
370          */
371         msgbuf[3] = hw->mac.mc_filter_type;
372         ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
373
374         return 0;
375 }
376
377 static int
378 ixgbe_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
379 {
380         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
381         struct ixgbe_vf_info *vfinfo = 
382                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
383         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
384         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
385
386         if (is_valid_assigned_ether_addr((struct ether_addr*)new_mac)) {
387                 rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac, 6);
388                 return hw->mac.ops.set_rar(hw, rar_entry, new_mac, vf, IXGBE_RAH_AV);
389         }
390         return -1;
391 }
392
393 static int
394 ixgbe_vf_set_multicast(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)
395 {
396         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
397         struct ixgbe_vf_info *vfinfo = 
398                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
399         int nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> 
400                 IXGBE_VT_MSGINFO_SHIFT;
401         uint16_t *hash_list = (uint16_t *)&msgbuf[1];
402         uint32_t mta_idx;
403         uint32_t mta_shift;
404         const uint32_t IXGBE_MTA_INDEX_MASK = 0x7F;
405         const uint32_t IXGBE_MTA_BIT_SHIFT = 5;
406         const uint32_t IXGBE_MTA_BIT_MASK = (0x1 << IXGBE_MTA_BIT_SHIFT) - 1;
407         uint32_t reg_val;
408         int i;
409                 
410         /* only so many hash values supported */
411         nb_entries = RTE_MIN(nb_entries, IXGBE_MAX_VF_MC_ENTRIES);
412
413         /* store the mc entries  */
414         vfinfo->num_vf_mc_hashes = (uint16_t)nb_entries;
415         for (i = 0; i < nb_entries; i++) {
416                 vfinfo->vf_mc_hashes[i] = hash_list[i];
417         }
418
419         for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
420                 mta_idx = (vfinfo->vf_mc_hashes[i] >> IXGBE_MTA_BIT_SHIFT) 
421                                 & IXGBE_MTA_INDEX_MASK;
422                 mta_shift = vfinfo->vf_mc_hashes[i] & IXGBE_MTA_BIT_MASK;
423                 reg_val = IXGBE_READ_REG(hw, IXGBE_MTA(mta_idx));
424                 reg_val |= (1 << mta_shift);
425                 IXGBE_WRITE_REG(hw, IXGBE_MTA(mta_idx), reg_val);
426         }
427
428         return 0;
429 }
430
431 static int
432 ixgbe_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
433 {
434         int add, vid;
435         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
436         struct ixgbe_vf_info *vfinfo = 
437                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
438
439         add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
440                 >> IXGBE_VT_MSGINFO_SHIFT;
441         vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
442
443         if (add)
444                 vfinfo[vf].vlan_count++;
445         else if (vfinfo[vf].vlan_count)
446                 vfinfo[vf].vlan_count--;
447         return hw->mac.ops.set_vfta(hw, vid, vf, (bool)add);
448 }
449
450 static int 
451 ixgbe_set_vf_lpe(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)
452 {
453         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
454         uint32_t new_mtu = msgbuf[1];
455         uint32_t max_frs;
456         int max_frame = new_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
457
458         /* Only X540 supports jumbo frames in IOV mode */
459         if (hw->mac.type != ixgbe_mac_X540)
460                 return -1;
461
462         if ((max_frame < ETHER_MIN_LEN) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN)) 
463                 return -1;
464
465         max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
466                    IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
467         if (max_frs < new_mtu) {
468                 max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
469                 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
470         }
471
472         return 0;
473 }
474
475 static int 
476 ixgbe_rcv_msg_from_vf(struct rte_eth_dev *dev, uint16_t vf)
477 {
478         uint16_t mbx_size = IXGBE_VFMAILBOX_SIZE;
479         uint32_t msgbuf[IXGBE_VFMAILBOX_SIZE];
480         int32_t retval;
481         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
482
483         retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
484         if (retval) {
485                 RTE_LOG(ERR, PMD, "Error mbx recv msg from VF %d\n", vf);
486                 return retval;
487         }
488
489         /* do nothing with the message already been processed */
490         if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
491                 return retval;
492
493         /* flush the ack before we write any messages back */
494         IXGBE_WRITE_FLUSH(hw);
495
496         /* perform VF reset */
497         if (msgbuf[0] == IXGBE_VF_RESET) {
498                 return ixgbe_vf_reset(dev, vf, msgbuf);
499         }
500
501         /* check & process VF to PF mailbox message */
502         switch ((msgbuf[0] & 0xFFFF)) {
503         case IXGBE_VF_SET_MAC_ADDR:
504                 retval = ixgbe_vf_set_mac_addr(dev, vf, msgbuf);
505                 break;
506         case IXGBE_VF_SET_MULTICAST:
507                 retval = ixgbe_vf_set_multicast(dev, vf, msgbuf);
508                 break;
509         case IXGBE_VF_SET_LPE:
510                 retval = ixgbe_set_vf_lpe(dev, vf, msgbuf);
511                 break;
512         case IXGBE_VF_SET_VLAN:
513                 retval = ixgbe_vf_set_vlan(dev, vf, msgbuf);
514                 break;
515         default:
516                 RTE_LOG(DEBUG, PMD, "Unhandled Msg %8.8x\n", (unsigned)  msgbuf[0]);
517                 retval = IXGBE_ERR_MBX;
518                 break;
519         }
520
521         /* response the VF according to the message process result */
522         if (retval)
523                 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
524         else
525                 msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
526
527         msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
528
529         ixgbe_write_mbx(hw, msgbuf, 1, vf);
530
531         return retval;
532 }
533
534 static inline void 
535 ixgbe_rcv_ack_from_vf(struct rte_eth_dev *dev, uint16_t vf)
536 {
537         uint32_t msg = IXGBE_VT_MSGTYPE_NACK;
538         struct ixgbe_hw *hw = 
539                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
540
541         ixgbe_write_mbx(hw, &msg, 1, vf);
542 }
543
544 void ixgbe_pf_mbx_process(struct rte_eth_dev *eth_dev)
545 {
546         uint16_t vf;
547         struct ixgbe_hw *hw = 
548                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
549
550         for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
551                 /* check & process vf function level reset */
552                 if (!ixgbe_check_for_rst(hw, vf))
553                         ixgbe_vf_reset_event(eth_dev, vf);
554
555                 /* check & process vf mailbox messages */
556                 if (!ixgbe_check_for_msg(hw, vf))
557                         ixgbe_rcv_msg_from_vf(eth_dev, vf);
558
559                 /* check & process acks from vf */
560                 if (!ixgbe_check_for_ack(hw, vf))
561                         ixgbe_rcv_ack_from_vf(eth_dev, vf);
562         }
563 }