1*e6550b3eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2*e6550b3eSThomas Gleixner // Copyright 2011 Cisco Systems, Inc.  All rights reserved.
3a6a5580cSJeff Kirsher 
4a6a5580cSJeff Kirsher #include <linux/kernel.h>
5a6a5580cSJeff Kirsher #include <linux/string.h>
6a6a5580cSJeff Kirsher #include <linux/errno.h>
7a6a5580cSJeff Kirsher #include <linux/types.h>
8a6a5580cSJeff Kirsher #include <linux/netdevice.h>
9a6a5580cSJeff Kirsher #include <linux/etherdevice.h>
10a6a5580cSJeff Kirsher #include <linux/rtnetlink.h>
11a6a5580cSJeff Kirsher #include <net/ip.h>
12a6a5580cSJeff Kirsher 
13a6a5580cSJeff Kirsher #include "vnic_vic.h"
14a6a5580cSJeff Kirsher #include "enic_res.h"
15a6a5580cSJeff Kirsher #include "enic.h"
16a6a5580cSJeff Kirsher #include "enic_dev.h"
173f192795SRoopa Prabhu #include "enic_pp.h"
18a6a5580cSJeff Kirsher 
193f192795SRoopa Prabhu /*
203f192795SRoopa Prabhu  * Checks validity of vf index that came in
213f192795SRoopa Prabhu  * port profile request
223f192795SRoopa Prabhu  */
enic_is_valid_pp_vf(struct enic * enic,int vf,int * err)233f192795SRoopa Prabhu int enic_is_valid_pp_vf(struct enic *enic, int vf, int *err)
243f192795SRoopa Prabhu {
253f192795SRoopa Prabhu 	if (vf != PORT_SELF_VF) {
263f192795SRoopa Prabhu #ifdef CONFIG_PCI_IOV
273f192795SRoopa Prabhu 		if (enic_sriov_enabled(enic)) {
283f192795SRoopa Prabhu 			if (vf < 0 || vf >= enic->num_vfs) {
293f192795SRoopa Prabhu 				*err = -EINVAL;
303f192795SRoopa Prabhu 				goto err_out;
313f192795SRoopa Prabhu 			}
323f192795SRoopa Prabhu 		} else {
333f192795SRoopa Prabhu 			*err = -EOPNOTSUPP;
343f192795SRoopa Prabhu 			goto err_out;
353f192795SRoopa Prabhu 		}
363f192795SRoopa Prabhu #else
373f192795SRoopa Prabhu 		*err = -EOPNOTSUPP;
383f192795SRoopa Prabhu 		goto err_out;
393f192795SRoopa Prabhu #endif
403f192795SRoopa Prabhu 	}
413f192795SRoopa Prabhu 
423f192795SRoopa Prabhu 	if (vf == PORT_SELF_VF && !enic_is_dynamic(enic)) {
433f192795SRoopa Prabhu 		*err = -EOPNOTSUPP;
443f192795SRoopa Prabhu 		goto err_out;
453f192795SRoopa Prabhu 	}
463f192795SRoopa Prabhu 
473f192795SRoopa Prabhu 	*err = 0;
483f192795SRoopa Prabhu 	return 1;
493f192795SRoopa Prabhu 
503f192795SRoopa Prabhu err_out:
513f192795SRoopa Prabhu 	return 0;
523f192795SRoopa Prabhu }
533f192795SRoopa Prabhu 
enic_set_port_profile(struct enic * enic,int vf)543f192795SRoopa Prabhu static int enic_set_port_profile(struct enic *enic, int vf)
55a6a5580cSJeff Kirsher {
56a6a5580cSJeff Kirsher 	struct net_device *netdev = enic->netdev;
573f192795SRoopa Prabhu 	struct enic_port_profile *pp;
58a6a5580cSJeff Kirsher 	struct vic_provinfo *vp;
59a6a5580cSJeff Kirsher 	const u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
6021ca54e9SSantosh Nayak 	const __be16 os_type = htons(VIC_GENERIC_PROV_OS_TYPE_LINUX);
6176660757SJakub Kicinski 	const u8 *client_mac;
62a6a5580cSJeff Kirsher 	char uuid_str[38];
63a6a5580cSJeff Kirsher 	char client_mac_str[18];
64a6a5580cSJeff Kirsher 	int err;
65a6a5580cSJeff Kirsher 
663f192795SRoopa Prabhu 	ENIC_PP_BY_INDEX(enic, vf, pp, &err);
673f192795SRoopa Prabhu 	if (err)
683f192795SRoopa Prabhu 		return err;
693f192795SRoopa Prabhu 
703f192795SRoopa Prabhu 	if (!(pp->set & ENIC_SET_NAME) || !strlen(pp->name))
71a6a5580cSJeff Kirsher 		return -EINVAL;
72a6a5580cSJeff Kirsher 
73a6a5580cSJeff Kirsher 	vp = vic_provinfo_alloc(GFP_KERNEL, oui,
74a6a5580cSJeff Kirsher 		VIC_PROVINFO_GENERIC_TYPE);
75a6a5580cSJeff Kirsher 	if (!vp)
76a6a5580cSJeff Kirsher 		return -ENOMEM;
77a6a5580cSJeff Kirsher 
78a6a5580cSJeff Kirsher 	VIC_PROVINFO_ADD_TLV(vp,
79a6a5580cSJeff Kirsher 		VIC_GENERIC_PROV_TLV_PORT_PROFILE_NAME_STR,
803f192795SRoopa Prabhu 		strlen(pp->name) + 1, pp->name);
81a6a5580cSJeff Kirsher 
823f192795SRoopa Prabhu 	if (!is_zero_ether_addr(pp->mac_addr)) {
833f192795SRoopa Prabhu 		client_mac = pp->mac_addr;
843f192795SRoopa Prabhu 	} else if (vf == PORT_SELF_VF) {
85a6a5580cSJeff Kirsher 		client_mac = netdev->dev_addr;
863f192795SRoopa Prabhu 	} else {
873f192795SRoopa Prabhu 		netdev_err(netdev, "Cannot find pp mac address "
883f192795SRoopa Prabhu 			"for VF %d\n", vf);
893f192795SRoopa Prabhu 		err = -EINVAL;
903f192795SRoopa Prabhu 		goto add_tlv_failure;
913f192795SRoopa Prabhu 	}
92a6a5580cSJeff Kirsher 
93a6a5580cSJeff Kirsher 	VIC_PROVINFO_ADD_TLV(vp,
94a6a5580cSJeff Kirsher 		VIC_GENERIC_PROV_TLV_CLIENT_MAC_ADDR,
95a6a5580cSJeff Kirsher 		ETH_ALEN, client_mac);
96a6a5580cSJeff Kirsher 
97a6a5580cSJeff Kirsher 	snprintf(client_mac_str, sizeof(client_mac_str), "%pM", client_mac);
98a6a5580cSJeff Kirsher 	VIC_PROVINFO_ADD_TLV(vp,
99a6a5580cSJeff Kirsher 		VIC_GENERIC_PROV_TLV_CLUSTER_PORT_UUID_STR,
100a6a5580cSJeff Kirsher 		sizeof(client_mac_str), client_mac_str);
101a6a5580cSJeff Kirsher 
1023f192795SRoopa Prabhu 	if (pp->set & ENIC_SET_INSTANCE) {
1033f192795SRoopa Prabhu 		sprintf(uuid_str, "%pUB", pp->instance_uuid);
104a6a5580cSJeff Kirsher 		VIC_PROVINFO_ADD_TLV(vp,
105a6a5580cSJeff Kirsher 			VIC_GENERIC_PROV_TLV_CLIENT_UUID_STR,
106a6a5580cSJeff Kirsher 			sizeof(uuid_str), uuid_str);
107a6a5580cSJeff Kirsher 	}
108a6a5580cSJeff Kirsher 
1093f192795SRoopa Prabhu 	if (pp->set & ENIC_SET_HOST) {
1103f192795SRoopa Prabhu 		sprintf(uuid_str, "%pUB", pp->host_uuid);
111a6a5580cSJeff Kirsher 		VIC_PROVINFO_ADD_TLV(vp,
112a6a5580cSJeff Kirsher 			VIC_GENERIC_PROV_TLV_HOST_UUID_STR,
113a6a5580cSJeff Kirsher 			sizeof(uuid_str), uuid_str);
114a6a5580cSJeff Kirsher 	}
115a6a5580cSJeff Kirsher 
116a6a5580cSJeff Kirsher 	VIC_PROVINFO_ADD_TLV(vp,
117a6a5580cSJeff Kirsher 		VIC_GENERIC_PROV_TLV_OS_TYPE,
118a6a5580cSJeff Kirsher 		sizeof(os_type), &os_type);
119a6a5580cSJeff Kirsher 
1203f192795SRoopa Prabhu 	ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_init_prov2, (u8 *)vp,
1213f192795SRoopa Prabhu 		vic_provinfo_size(vp));
1223f192795SRoopa Prabhu 	err = enic_dev_status_to_errno(err);
123a6a5580cSJeff Kirsher 
124a6a5580cSJeff Kirsher add_tlv_failure:
125a6a5580cSJeff Kirsher 	vic_provinfo_free(vp);
126a6a5580cSJeff Kirsher 
127a6a5580cSJeff Kirsher 	return err;
128a6a5580cSJeff Kirsher }
129a6a5580cSJeff Kirsher 
enic_unset_port_profile(struct enic * enic,int vf)1303f192795SRoopa Prabhu static int enic_unset_port_profile(struct enic *enic, int vf)
131a6a5580cSJeff Kirsher {
132a6a5580cSJeff Kirsher 	int err;
133a6a5580cSJeff Kirsher 
1343f192795SRoopa Prabhu 	ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_deinit);
135a6a5580cSJeff Kirsher 	if (err)
136a6a5580cSJeff Kirsher 		return enic_dev_status_to_errno(err);
137a6a5580cSJeff Kirsher 
1383f192795SRoopa Prabhu 	if (vf == PORT_SELF_VF)
139a6a5580cSJeff Kirsher 		enic_reset_addr_lists(enic);
140a6a5580cSJeff Kirsher 
141a6a5580cSJeff Kirsher 	return 0;
142a6a5580cSJeff Kirsher }
143a6a5580cSJeff Kirsher 
enic_are_pp_different(struct enic_port_profile * pp1,struct enic_port_profile * pp2)144a6a5580cSJeff Kirsher static int enic_are_pp_different(struct enic_port_profile *pp1,
145a6a5580cSJeff Kirsher 		struct enic_port_profile *pp2)
146a6a5580cSJeff Kirsher {
147a6a5580cSJeff Kirsher 	return strcmp(pp1->name, pp2->name) | !!memcmp(pp1->instance_uuid,
148a6a5580cSJeff Kirsher 		pp2->instance_uuid, PORT_UUID_MAX) |
149a6a5580cSJeff Kirsher 		!!memcmp(pp1->host_uuid, pp2->host_uuid, PORT_UUID_MAX) |
1509130ac61Sdingtianhong 		!ether_addr_equal(pp1->mac_addr, pp2->mac_addr);
151a6a5580cSJeff Kirsher }
152a6a5580cSJeff Kirsher 
1533f192795SRoopa Prabhu static int enic_pp_preassociate(struct enic *enic, int vf,
154a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp);
1553f192795SRoopa Prabhu static int enic_pp_disassociate(struct enic *enic, int vf,
156a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp);
1573f192795SRoopa Prabhu static int enic_pp_preassociate_rr(struct enic *enic, int vf,
158a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp);
1593f192795SRoopa Prabhu static int enic_pp_associate(struct enic *enic, int vf,
160a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp);
161a6a5580cSJeff Kirsher 
1623f192795SRoopa Prabhu static int (*enic_pp_handlers[])(struct enic *enic, int vf,
1633f192795SRoopa Prabhu 		struct enic_port_profile *prev_state,
1643f192795SRoopa Prabhu 		int *restore_pp) = {
165a6a5580cSJeff Kirsher 	[PORT_REQUEST_PREASSOCIATE]	= enic_pp_preassociate,
166a6a5580cSJeff Kirsher 	[PORT_REQUEST_PREASSOCIATE_RR]	= enic_pp_preassociate_rr,
167a6a5580cSJeff Kirsher 	[PORT_REQUEST_ASSOCIATE]	= enic_pp_associate,
168a6a5580cSJeff Kirsher 	[PORT_REQUEST_DISASSOCIATE]	= enic_pp_disassociate,
169a6a5580cSJeff Kirsher };
170a6a5580cSJeff Kirsher 
171a6a5580cSJeff Kirsher static const int enic_pp_handlers_count =
1724133099bSJim Cromie 			ARRAY_SIZE(enic_pp_handlers);
173a6a5580cSJeff Kirsher 
enic_pp_preassociate(struct enic * enic,int vf,struct enic_port_profile * prev_pp,int * restore_pp)1743f192795SRoopa Prabhu static int enic_pp_preassociate(struct enic *enic, int vf,
175a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp)
176a6a5580cSJeff Kirsher {
177a6a5580cSJeff Kirsher 	return -EOPNOTSUPP;
178a6a5580cSJeff Kirsher }
179a6a5580cSJeff Kirsher 
enic_pp_disassociate(struct enic * enic,int vf,struct enic_port_profile * prev_pp,int * restore_pp)1803f192795SRoopa Prabhu static int enic_pp_disassociate(struct enic *enic, int vf,
181a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp)
182a6a5580cSJeff Kirsher {
1833f192795SRoopa Prabhu 	struct net_device *netdev = enic->netdev;
1843f192795SRoopa Prabhu 	struct enic_port_profile *pp;
1853f192795SRoopa Prabhu 	int err;
1863f192795SRoopa Prabhu 
1873f192795SRoopa Prabhu 	ENIC_PP_BY_INDEX(enic, vf, pp, &err);
1883f192795SRoopa Prabhu 	if (err)
1893f192795SRoopa Prabhu 		return err;
1903f192795SRoopa Prabhu 
1913f192795SRoopa Prabhu 	/* Deregister mac addresses */
1923f192795SRoopa Prabhu 	if (!is_zero_ether_addr(pp->mac_addr))
1933f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_del_addr,
1943f192795SRoopa Prabhu 			pp->mac_addr);
1959f1de88dSRoopa Prabhu 	else if (vf == PORT_SELF_VF && !is_zero_ether_addr(netdev->dev_addr))
1963f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_del_addr,
1973f192795SRoopa Prabhu 			netdev->dev_addr);
1983f192795SRoopa Prabhu 
1993f192795SRoopa Prabhu 	return enic_unset_port_profile(enic, vf);
200a6a5580cSJeff Kirsher }
201a6a5580cSJeff Kirsher 
enic_pp_preassociate_rr(struct enic * enic,int vf,struct enic_port_profile * prev_pp,int * restore_pp)2023f192795SRoopa Prabhu static int enic_pp_preassociate_rr(struct enic *enic, int vf,
203a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp)
204a6a5580cSJeff Kirsher {
2053f192795SRoopa Prabhu 	struct enic_port_profile *pp;
206a6a5580cSJeff Kirsher 	int err;
207a6a5580cSJeff Kirsher 	int active = 0;
208a6a5580cSJeff Kirsher 
2093f192795SRoopa Prabhu 	ENIC_PP_BY_INDEX(enic, vf, pp, &err);
2103f192795SRoopa Prabhu 	if (err)
2113f192795SRoopa Prabhu 		return err;
2123f192795SRoopa Prabhu 
2133f192795SRoopa Prabhu 	if (pp->request != PORT_REQUEST_ASSOCIATE) {
214a6a5580cSJeff Kirsher 		/* If pre-associate is not part of an associate.
215a6a5580cSJeff Kirsher 		We always disassociate first */
2163f192795SRoopa Prabhu 		err = enic_pp_handlers[PORT_REQUEST_DISASSOCIATE](enic, vf,
217a6a5580cSJeff Kirsher 			prev_pp, restore_pp);
218a6a5580cSJeff Kirsher 		if (err)
219a6a5580cSJeff Kirsher 			return err;
220a6a5580cSJeff Kirsher 
221a6a5580cSJeff Kirsher 		*restore_pp = 0;
222a6a5580cSJeff Kirsher 	}
223a6a5580cSJeff Kirsher 
224a6a5580cSJeff Kirsher 	*restore_pp = 0;
225a6a5580cSJeff Kirsher 
2263f192795SRoopa Prabhu 	err = enic_set_port_profile(enic, vf);
227a6a5580cSJeff Kirsher 	if (err)
228a6a5580cSJeff Kirsher 		return err;
229a6a5580cSJeff Kirsher 
230a6a5580cSJeff Kirsher 	/* If pre-associate is not part of an associate. */
2313f192795SRoopa Prabhu 	if (pp->request != PORT_REQUEST_ASSOCIATE) {
2323f192795SRoopa Prabhu 		/* Enable device as standby */
2333f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_enable2,
2343f192795SRoopa Prabhu 			active);
2353f192795SRoopa Prabhu 		err = enic_dev_status_to_errno(err);
2363f192795SRoopa Prabhu 	}
237a6a5580cSJeff Kirsher 
238a6a5580cSJeff Kirsher 	return err;
239a6a5580cSJeff Kirsher }
240a6a5580cSJeff Kirsher 
enic_pp_associate(struct enic * enic,int vf,struct enic_port_profile * prev_pp,int * restore_pp)2413f192795SRoopa Prabhu static int enic_pp_associate(struct enic *enic, int vf,
242a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp)
243a6a5580cSJeff Kirsher {
2443f192795SRoopa Prabhu 	struct net_device *netdev = enic->netdev;
2453f192795SRoopa Prabhu 	struct enic_port_profile *pp;
246a6a5580cSJeff Kirsher 	int err;
247a6a5580cSJeff Kirsher 	int active = 1;
248a6a5580cSJeff Kirsher 
2493f192795SRoopa Prabhu 	ENIC_PP_BY_INDEX(enic, vf, pp, &err);
2503f192795SRoopa Prabhu 	if (err)
2513f192795SRoopa Prabhu 		return err;
2523f192795SRoopa Prabhu 
253a6a5580cSJeff Kirsher 	/* Check if a pre-associate was called before */
254a6a5580cSJeff Kirsher 	if (prev_pp->request != PORT_REQUEST_PREASSOCIATE_RR ||
255a6a5580cSJeff Kirsher 		(prev_pp->request == PORT_REQUEST_PREASSOCIATE_RR &&
2563f192795SRoopa Prabhu 			enic_are_pp_different(prev_pp, pp))) {
257a6a5580cSJeff Kirsher 		err = enic_pp_handlers[PORT_REQUEST_DISASSOCIATE](
2583f192795SRoopa Prabhu 			enic, vf, prev_pp, restore_pp);
259a6a5580cSJeff Kirsher 		if (err)
260a6a5580cSJeff Kirsher 			return err;
261a6a5580cSJeff Kirsher 
262a6a5580cSJeff Kirsher 		*restore_pp = 0;
263a6a5580cSJeff Kirsher 	}
264a6a5580cSJeff Kirsher 
265a6a5580cSJeff Kirsher 	err = enic_pp_handlers[PORT_REQUEST_PREASSOCIATE_RR](
2663f192795SRoopa Prabhu 			enic, vf, prev_pp, restore_pp);
267a6a5580cSJeff Kirsher 	if (err)
268a6a5580cSJeff Kirsher 		return err;
269a6a5580cSJeff Kirsher 
270a6a5580cSJeff Kirsher 	*restore_pp = 0;
271a6a5580cSJeff Kirsher 
2723f192795SRoopa Prabhu 	/* Enable device as active */
2733f192795SRoopa Prabhu 	ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_enable2, active);
2743f192795SRoopa Prabhu 	err = enic_dev_status_to_errno(err);
2753f192795SRoopa Prabhu 	if (err)
2763f192795SRoopa Prabhu 		return err;
2773f192795SRoopa Prabhu 
2783f192795SRoopa Prabhu 	/* Register mac address */
2793f192795SRoopa Prabhu 	if (!is_zero_ether_addr(pp->mac_addr))
2803f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_add_addr,
2813f192795SRoopa Prabhu 			pp->mac_addr);
2829f1de88dSRoopa Prabhu 	else if (vf == PORT_SELF_VF && !is_zero_ether_addr(netdev->dev_addr))
2833f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, vnic_dev_add_addr,
2843f192795SRoopa Prabhu 			netdev->dev_addr);
2853f192795SRoopa Prabhu 
2863f192795SRoopa Prabhu 	return 0;
287a6a5580cSJeff Kirsher }
288a6a5580cSJeff Kirsher 
enic_process_set_pp_request(struct enic * enic,int vf,struct enic_port_profile * prev_pp,int * restore_pp)2893f192795SRoopa Prabhu int enic_process_set_pp_request(struct enic *enic, int vf,
290a6a5580cSJeff Kirsher 	struct enic_port_profile *prev_pp, int *restore_pp)
291a6a5580cSJeff Kirsher {
2923f192795SRoopa Prabhu 	struct enic_port_profile *pp;
2933f192795SRoopa Prabhu 	int err;
2943f192795SRoopa Prabhu 
2953f192795SRoopa Prabhu 	ENIC_PP_BY_INDEX(enic, vf, pp, &err);
2963f192795SRoopa Prabhu 	if (err)
2973f192795SRoopa Prabhu 		return err;
2983f192795SRoopa Prabhu 
2993f192795SRoopa Prabhu 	if (pp->request >= enic_pp_handlers_count
3003f192795SRoopa Prabhu 		|| !enic_pp_handlers[pp->request])
301a6a5580cSJeff Kirsher 		return -EOPNOTSUPP;
3023f192795SRoopa Prabhu 
3033f192795SRoopa Prabhu 	return enic_pp_handlers[pp->request](enic, vf, prev_pp, restore_pp);
304a6a5580cSJeff Kirsher }
305a6a5580cSJeff Kirsher 
enic_process_get_pp_request(struct enic * enic,int vf,int request,u16 * response)3063f192795SRoopa Prabhu int enic_process_get_pp_request(struct enic *enic, int vf,
3073f192795SRoopa Prabhu 	int request, u16 *response)
308a6a5580cSJeff Kirsher {
309a6a5580cSJeff Kirsher 	int err, status = ERR_SUCCESS;
310a6a5580cSJeff Kirsher 
311a6a5580cSJeff Kirsher 	switch (request) {
312a6a5580cSJeff Kirsher 
313a6a5580cSJeff Kirsher 	case PORT_REQUEST_PREASSOCIATE_RR:
314a6a5580cSJeff Kirsher 	case PORT_REQUEST_ASSOCIATE:
3153f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic,
3163f192795SRoopa Prabhu 			vnic_dev_enable2_done, &status);
317a6a5580cSJeff Kirsher 		break;
318a6a5580cSJeff Kirsher 
319a6a5580cSJeff Kirsher 	case PORT_REQUEST_DISASSOCIATE:
3203f192795SRoopa Prabhu 		ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic,
3213f192795SRoopa Prabhu 			vnic_dev_deinit_done, &status);
322a6a5580cSJeff Kirsher 		break;
323a6a5580cSJeff Kirsher 
324a6a5580cSJeff Kirsher 	default:
325a6a5580cSJeff Kirsher 		return -EINVAL;
326a6a5580cSJeff Kirsher 	}
327a6a5580cSJeff Kirsher 
328a6a5580cSJeff Kirsher 	if (err)
329a6a5580cSJeff Kirsher 		status = err;
330a6a5580cSJeff Kirsher 
331a6a5580cSJeff Kirsher 	switch (status) {
332a6a5580cSJeff Kirsher 	case ERR_SUCCESS:
333a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_SUCCESS;
334a6a5580cSJeff Kirsher 		break;
335a6a5580cSJeff Kirsher 	case ERR_EINVAL:
336a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_INVALID;
337a6a5580cSJeff Kirsher 		break;
338a6a5580cSJeff Kirsher 	case ERR_EBADSTATE:
339a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_BADSTATE;
340a6a5580cSJeff Kirsher 		break;
341a6a5580cSJeff Kirsher 	case ERR_ENOMEM:
342a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
343a6a5580cSJeff Kirsher 		break;
344a6a5580cSJeff Kirsher 	case ERR_EINPROGRESS:
345a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_INPROGRESS;
346a6a5580cSJeff Kirsher 		break;
347a6a5580cSJeff Kirsher 	default:
348a6a5580cSJeff Kirsher 		*response = PORT_PROFILE_RESPONSE_ERROR;
349a6a5580cSJeff Kirsher 		break;
350a6a5580cSJeff Kirsher 	}
351a6a5580cSJeff Kirsher 
352a6a5580cSJeff Kirsher 	return 0;
353a6a5580cSJeff Kirsher }
354