]> Pileus Git - ~andy/linux/blob - drivers/net/ethernet/intel/i40evf/i40e_common.c
Bluetooth: remove direct compilation of 6lowpan_iphc.c
[~andy/linux] / drivers / net / ethernet / intel / i40evf / i40e_common.c
1 /*******************************************************************************
2  *
3  * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4  * Copyright(c) 2013 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * The full GNU General Public License is included in this distribution in
16  * the file called "COPYING".
17  *
18  * Contact Information:
19  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
20  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21  *
22  ******************************************************************************/
23
24 #include "i40e_type.h"
25 #include "i40e_adminq.h"
26 #include "i40e_prototype.h"
27 #include "i40e_virtchnl.h"
28
29 /**
30  * i40e_set_mac_type - Sets MAC type
31  * @hw: pointer to the HW structure
32  *
33  * This function sets the mac type of the adapter based on the
34  * vendor ID and device ID stored in the hw structure.
35  **/
36 i40e_status i40e_set_mac_type(struct i40e_hw *hw)
37 {
38         i40e_status status = 0;
39
40         if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
41                 switch (hw->device_id) {
42                 case I40E_SFP_XL710_DEVICE_ID:
43                 case I40E_SFP_X710_DEVICE_ID:
44                 case I40E_QEMU_DEVICE_ID:
45                 case I40E_KX_A_DEVICE_ID:
46                 case I40E_KX_B_DEVICE_ID:
47                 case I40E_KX_C_DEVICE_ID:
48                 case I40E_KX_D_DEVICE_ID:
49                 case I40E_QSFP_A_DEVICE_ID:
50                 case I40E_QSFP_B_DEVICE_ID:
51                 case I40E_QSFP_C_DEVICE_ID:
52                         hw->mac.type = I40E_MAC_XL710;
53                         break;
54                 case I40E_VF_DEVICE_ID:
55                 case I40E_VF_HV_DEVICE_ID:
56                         hw->mac.type = I40E_MAC_VF;
57                         break;
58                 default:
59                         hw->mac.type = I40E_MAC_GENERIC;
60                         break;
61                 }
62         } else {
63                 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
64         }
65
66         hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
67                   hw->mac.type, status);
68         return status;
69 }
70
71 /**
72  * i40evf_debug_aq
73  * @hw: debug mask related to admin queue
74  * @mask: debug mask
75  * @desc: pointer to admin queue descriptor
76  * @buffer: pointer to command buffer
77  *
78  * Dumps debug log about adminq command with descriptor contents.
79  **/
80 void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
81                    void *buffer)
82 {
83         struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
84         u8 *aq_buffer = (u8 *)buffer;
85         u32 data[4];
86         u32 i = 0;
87
88         if ((!(mask & hw->debug_mask)) || (desc == NULL))
89                 return;
90
91         i40e_debug(hw, mask,
92                    "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
93                    aq_desc->opcode, aq_desc->flags, aq_desc->datalen,
94                    aq_desc->retval);
95         i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
96                    aq_desc->cookie_high, aq_desc->cookie_low);
97         i40e_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
98                    aq_desc->params.internal.param0,
99                    aq_desc->params.internal.param1);
100         i40e_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
101                    aq_desc->params.external.addr_high,
102                    aq_desc->params.external.addr_low);
103
104         if ((buffer != NULL) && (aq_desc->datalen != 0)) {
105                 memset(data, 0, sizeof(data));
106                 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
107                 for (i = 0; i < le16_to_cpu(aq_desc->datalen); i++) {
108                         data[((i % 16) / 4)] |=
109                                 ((u32)aq_buffer[i]) << (8 * (i % 4));
110                         if ((i % 16) == 15) {
111                                 i40e_debug(hw, mask,
112                                            "\t0x%04X  %08X %08X %08X %08X\n",
113                                            i - 15, data[0], data[1], data[2],
114                                            data[3]);
115                                 memset(data, 0, sizeof(data));
116                         }
117                 }
118                 if ((i % 16) != 0)
119                         i40e_debug(hw, mask, "\t0x%04X  %08X %08X %08X %08X\n",
120                                    i - (i % 16), data[0], data[1], data[2],
121                                    data[3]);
122         }
123 }
124
125 /**
126  * i40evf_check_asq_alive
127  * @hw: pointer to the hw struct
128  *
129  * Returns true if Queue is enabled else false.
130  **/
131 bool i40evf_check_asq_alive(struct i40e_hw *hw)
132 {
133         return !!(rd32(hw, hw->aq.asq.len) & I40E_PF_ATQLEN_ATQENABLE_MASK);
134 }
135
136 /**
137  * i40evf_aq_queue_shutdown
138  * @hw: pointer to the hw struct
139  * @unloading: is the driver unloading itself
140  *
141  * Tell the Firmware that we're shutting down the AdminQ and whether
142  * or not the driver is unloading as well.
143  **/
144 i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
145                                              bool unloading)
146 {
147         struct i40e_aq_desc desc;
148         struct i40e_aqc_queue_shutdown *cmd =
149                 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
150         i40e_status status;
151
152         i40evf_fill_default_direct_cmd_desc(&desc,
153                                           i40e_aqc_opc_queue_shutdown);
154
155         if (unloading)
156                 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
157         status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
158
159         return status;
160 }
161
162
163 /**
164  * i40e_aq_send_msg_to_pf
165  * @hw: pointer to the hardware structure
166  * @v_opcode: opcodes for VF-PF communication
167  * @v_retval: return error code
168  * @msg: pointer to the msg buffer
169  * @msglen: msg length
170  * @cmd_details: pointer to command details
171  *
172  * Send message to PF driver using admin queue. By default, this message
173  * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
174  * completion before returning.
175  **/
176 i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
177                                 enum i40e_virtchnl_ops v_opcode,
178                                 i40e_status v_retval,
179                                 u8 *msg, u16 msglen,
180                                 struct i40e_asq_cmd_details *cmd_details)
181 {
182         struct i40e_aq_desc desc;
183         i40e_status status;
184
185         i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
186         desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
187         desc.cookie_high = cpu_to_le32(v_opcode);
188         desc.cookie_low = cpu_to_le32(v_retval);
189         if (msglen) {
190                 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
191                                                 | I40E_AQ_FLAG_RD));
192                 if (msglen > I40E_AQ_LARGE_BUF)
193                         desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
194                 desc.datalen = cpu_to_le16(msglen);
195         }
196         if (!cmd_details) {
197                 struct i40e_asq_cmd_details details;
198                 memset(&details, 0, sizeof(details));
199                 details.async = true;
200                 cmd_details = &details;
201         }
202         status = i40evf_asq_send_command(hw, (struct i40e_aq_desc *)&desc, msg,
203                                        msglen, cmd_details);
204         return status;
205 }
206
207 /**
208  * i40e_vf_parse_hw_config
209  * @hw: pointer to the hardware structure
210  * @msg: pointer to the virtual channel VF resource structure
211  *
212  * Given a VF resource message from the PF, populate the hw struct
213  * with appropriate information.
214  **/
215 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
216                              struct i40e_virtchnl_vf_resource *msg)
217 {
218         struct i40e_virtchnl_vsi_resource *vsi_res;
219         int i;
220
221         vsi_res = &msg->vsi_res[0];
222
223         hw->dev_caps.num_vsis = msg->num_vsis;
224         hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
225         hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
226         hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
227         hw->dev_caps.dcb = msg->vf_offload_flags &
228                            I40E_VIRTCHNL_VF_OFFLOAD_L2;
229         hw->dev_caps.fcoe = (msg->vf_offload_flags &
230                              I40E_VIRTCHNL_VF_OFFLOAD_FCOE) ? 1 : 0;
231         for (i = 0; i < msg->num_vsis; i++) {
232                 if (vsi_res->vsi_type == I40E_VSI_SRIOV) {
233                         memcpy(hw->mac.perm_addr, vsi_res->default_mac_addr,
234                                ETH_ALEN);
235                         memcpy(hw->mac.addr, vsi_res->default_mac_addr,
236                                ETH_ALEN);
237                 }
238                 vsi_res++;
239         }
240 }
241
242 /**
243  * i40e_vf_reset
244  * @hw: pointer to the hardware structure
245  *
246  * Send a VF_RESET message to the PF. Does not wait for response from PF
247  * as none will be forthcoming. Immediately after calling this function,
248  * the admin queue should be shut down and (optionally) reinitialized.
249  **/
250 i40e_status i40e_vf_reset(struct i40e_hw *hw)
251 {
252         return i40e_aq_send_msg_to_pf(hw, I40E_VIRTCHNL_OP_RESET_VF,
253                                       0, NULL, 0, NULL);
254 }