/* * Copyright(c) 2017 Intel Corporation. * Copyright(c) 2021 Cornelis Networks. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * BSD LICENSE * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*/
/* * The trap service level is kept in bits 3 to 7 in the trap_sl_rsvd * field in the class port info MAD.
*/ #define GET_TRAP_SL_FROM_CLASS_PORT_INFO(x) (((x) >> 3) & 0x1f)
/* Cap trap bursts to a reasonable limit good for normal cases */ #define OPA_VNIC_TRAP_BURST_LIMIT 4
/* * VNIC trap limit timeout. * Inverse of cap2_mask response time out (1.0737 secs) = 0.9 * secs approx IB spec 13.4.6.2.1 PortInfoSubnetTimeout and * 13.4.9 Traps.
*/ #define OPA_VNIC_TRAP_TIMEOUT ((4096 * (1UL << 18)) / 1000)
/** * vema_get_vport_num -- Get the vnic from the mad * @recvd_mad: Received mad * * Return: returns value of the vnic port number
*/ staticinline u8 vema_get_vport_num(struct opa_vnic_vema_mad *recvd_mad)
{ return be32_to_cpu(recvd_mad->mad_hdr.attr_mod) & 0xff;
}
/** * vema_get_vport_adapter -- Get vnic port adapter from recvd mad * @recvd_mad: received mad * @port: ptr to port struct on which MAD was recvd * * Return: vnic adapter
*/ staticinlinestruct opa_vnic_adapter *
vema_get_vport_adapter(struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_port *port)
{
u8 vport_num = vema_get_vport_num(recvd_mad);
return xa_load(&port->vports, vport_num);
}
/** * vema_mac_tbl_req_ok -- Check if mac request has correct values * @mac_tbl: mac table * * This function checks for the validity of the offset and number of * entries required. * * Return: true if offset and num_entries are valid
*/ staticinlinebool vema_mac_tbl_req_ok(struct opa_veswport_mactable *mac_tbl)
{
u16 offset, num_entries;
u16 req_entries = ((OPA_VNIC_EMA_DATA - sizeof(*mac_tbl)) / sizeof(mac_tbl->tbl_entries[0]));
/* * Return the power on default values in the port info structure * in big endian format as required by MAD.
*/ staticinlinevoid vema_get_pod_values(struct opa_veswport_info *port_info)
{
memset(port_info, 0, sizeof(*port_info));
port_info->vport.max_mac_tbl_ent =
cpu_to_be16(OPA_VNIC_MAC_TBL_MAX_ENTRIES);
port_info->vport.max_smac_ent =
cpu_to_be16(OPA_VNIC_MAX_SMAC_LIMIT);
port_info->vport.oper_state = OPA_VNIC_STATE_DROP_ALL;
port_info->vport.config_state = OPA_VNIC_STATE_DROP_ALL;
port_info->vesw.eth_mtu = cpu_to_be16(ETH_DATA_LEN);
}
/** * vema_add_vport -- Add a new vnic port * @port: ptr to opa_vnic_vema_port struct * @vport_num: vnic port number (to be added) * * Return a pointer to the vnic adapter structure
*/ staticstruct opa_vnic_adapter *vema_add_vport(struct opa_vnic_vema_port *port,
u8 vport_num)
{ struct opa_vnic_ctrl_port *cport = port->cport; struct opa_vnic_adapter *adapter;
adapter = opa_vnic_add_netdev(cport->ibdev, port->port_num, vport_num); if (!IS_ERR(adapter)) { int rc;
/** * vema_get_class_port_info -- Get class info for port * @port: Port on whic MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function copies the latest class port info value set for the * port and stores it for generating traps
*/ staticvoid vema_get_class_port_info(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_class_port_info *port_info;
/* * Set capability mask bit indicating agent generates traps, * and set the maximum number of VNIC ports supported.
*/
port_info->cap_mask = cpu_to_be16((OPA_VNIC_CLASS_CAP_TRAP |
(OPA_VNIC_MAX_NUM_VPORT << 8)));
/* * Since a get routine is always sent by the EM first we * set the expected response time to * 4.096 usec * 2^18 == 1.0737 sec here.
*/
port_info->cap_mask2_resp_time = cpu_to_be32(18);
}
/** * vema_set_class_port_info -- Get class info for port * @port: Port on whic MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function updates the port class info for the specific vnic * and sets up the response mad data
*/ staticvoid vema_set_class_port_info(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{
memcpy(&port->class_port_info, recvd_mad->data, sizeof(port->class_port_info));
/** * vema_get_veswport_info -- Get veswport info * @port: source port on which MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad
*/ staticvoid vema_get_veswport_info(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_info *port_info =
(struct opa_veswport_info *)rsp_mad->data; struct opa_vnic_adapter *adapter;
/** * vema_set_veswport_info -- Set veswport info * @port: source port on which MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function gets the port class infor for vnic
*/ staticvoid vema_set_veswport_info(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_vnic_ctrl_port *cport = port->cport; struct opa_veswport_info *port_info; struct opa_vnic_adapter *adapter;
u8 vport_num;
vport_num = vema_get_vport_num(recvd_mad);
adapter = vema_get_vport_adapter(recvd_mad, port); if (!adapter) {
adapter = vema_add_vport(port, vport_num); if (IS_ERR(adapter)) {
c_err("failed to add vport %d: %ld\n",
vport_num, PTR_ERR(adapter)); goto err_exit;
}
}
/** * vema_get_mac_entries -- Get MAC entries in VNIC MAC table * @port: source port on which MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function gets the MAC entries that are programmed into * the VNIC MAC forwarding table. It checks for the validity of * the index into the MAC table and the number of entries that * are to be retrieved.
*/ staticvoid vema_get_mac_entries(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_mactable *mac_tbl_in, *mac_tbl_out; struct opa_vnic_adapter *adapter;
/** * vema_set_mac_entries -- Set MAC entries in VNIC MAC table * @port: source port on which MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function sets the MAC entries in the VNIC forwarding table * It checks for the validity of the index and the number of forwarding * table entries to be programmed.
*/ staticvoid vema_set_mac_entries(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_mactable *mac_tbl; struct opa_vnic_adapter *adapter;
/** * vema_set_delete_vesw -- Reset VESW info to POD values * @port: source port on which MAD was received * @recvd_mad: pointer to the received mad * @rsp_mad: pointer to respose mad * * This function clears all the fields of veswport info for the requested vesw * and sets them back to the power-on default values. It does not delete the * vesw.
*/ staticvoid vema_set_delete_vesw(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_info *port_info =
(struct opa_veswport_info *)rsp_mad->data; struct opa_vnic_adapter *adapter;
/** * vema_get_mac_list -- Get the unicast/multicast macs. * @port: source port on which MAD was received * @recvd_mad: Received mad contains fields to set vnic parameters * @rsp_mad: Response mad to be built * @attr_id: Attribute ID indicating multicast or unicast mac list
*/ staticvoid vema_get_mac_list(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad,
u16 attr_id)
{ struct opa_veswport_iface_macs *macs_in, *macs_out; int max_entries = (OPA_VNIC_EMA_DATA - sizeof(*macs_out)) / ETH_ALEN; struct opa_vnic_adapter *adapter;
if (attr_id == OPA_EM_ATTR_IFACE_MCAST_MACS)
opa_vnic_query_mcast_macs(adapter, macs_out); else
opa_vnic_query_ucast_macs(adapter, macs_out);
}
/** * vema_get_summary_counters -- Gets summary counters. * @port: source port on which MAD was received * @recvd_mad: Received mad contains fields to set vnic parameters * @rsp_mad: Response mad to be built
*/ staticvoid vema_get_summary_counters(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_summary_counters *cntrs; struct opa_vnic_adapter *adapter;
/** * vema_get_error_counters -- Gets summary counters. * @port: source port on which MAD was received * @recvd_mad: Received mad contains fields to set vnic parameters * @rsp_mad: Response mad to be built
*/ staticvoid vema_get_error_counters(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{ struct opa_veswport_error_counters *cntrs; struct opa_vnic_adapter *adapter;
/** * vema_get -- Process received get MAD * @port: source port on which MAD was received * @recvd_mad: Received mad * @rsp_mad: Response mad to be built
*/ staticvoid vema_get(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{
u16 attr_id = be16_to_cpu(recvd_mad->mad_hdr.attr_id);
switch (attr_id) { case OPA_EM_ATTR_CLASS_PORT_INFO:
vema_get_class_port_info(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_VESWPORT_INFO:
vema_get_veswport_info(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_VESWPORT_MAC_ENTRIES:
vema_get_mac_entries(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_IFACE_UCAST_MACS: case OPA_EM_ATTR_IFACE_MCAST_MACS:
vema_get_mac_list(port, recvd_mad, rsp_mad, attr_id); break; case OPA_EM_ATTR_VESWPORT_SUMMARY_COUNTERS:
vema_get_summary_counters(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_VESWPORT_ERROR_COUNTERS:
vema_get_error_counters(port, recvd_mad, rsp_mad); break; default:
rsp_mad->mad_hdr.status = OPA_VNIC_UNSUP_ATTR; break;
}
}
/** * vema_set -- Process received set MAD * @port: source port on which MAD was received * @recvd_mad: Received mad contains fields to set vnic parameters * @rsp_mad: Response mad to be built
*/ staticvoid vema_set(struct opa_vnic_vema_port *port, struct opa_vnic_vema_mad *recvd_mad, struct opa_vnic_vema_mad *rsp_mad)
{
u16 attr_id = be16_to_cpu(recvd_mad->mad_hdr.attr_id);
switch (attr_id) { case OPA_EM_ATTR_CLASS_PORT_INFO:
vema_set_class_port_info(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_VESWPORT_INFO:
vema_set_veswport_info(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_VESWPORT_MAC_ENTRIES:
vema_set_mac_entries(port, recvd_mad, rsp_mad); break; case OPA_EM_ATTR_DELETE_VESW:
vema_set_delete_vesw(port, recvd_mad, rsp_mad); break; default:
rsp_mad->mad_hdr.status = OPA_VNIC_UNSUP_ATTR; break;
}
}
/** * vema_send -- Send handler for VEMA MAD agent * @mad_agent: pointer to the mad agent * @mad_wc: pointer to mad send work completion information * * Free all the data structures associated with the sent MAD
*/ staticvoid vema_send(struct ib_mad_agent *mad_agent, struct ib_mad_send_wc *mad_wc)
{
rdma_destroy_ah(mad_wc->send_buf->ah, RDMA_DESTROY_AH_SLEEPABLE);
ib_free_send_mad(mad_wc->send_buf);
}
/** * vema_recv -- Recv handler for VEMA MAD agent * @mad_agent: pointer to the mad agent * @send_buf: Send buffer if found, else NULL * @mad_wc: pointer to mad send work completion information * * Handle only set and get methods and respond to other methods * as unsupported. Allocate response buffer and address handle * for the response MAD.
*/ staticvoid vema_recv(struct ib_mad_agent *mad_agent, struct ib_mad_send_buf *send_buf, struct ib_mad_recv_wc *mad_wc)
{ struct opa_vnic_vema_port *port; struct ib_ah *ah; struct ib_mad_send_buf *rsp; struct opa_vnic_vema_mad *vema_mad;
if (!mad_wc || !mad_wc->recv_buf.mad) return;
port = mad_agent->context;
ah = ib_create_ah_from_wc(mad_agent->qp->pd, mad_wc->wc,
mad_wc->recv_buf.grh, mad_agent->port_num); if (IS_ERR(ah)) goto free_recv_mad;
/** * vema_get_port -- Gets the opa_vnic_vema_port * @cport: pointer to control dev * @port_num: Port number * * This function loops through the ports and returns * the opa_vnic_vema port structure that is associated * with the OPA port number * * Return: ptr to requested opa_vnic_vema_port strucure * if success, NULL if not
*/ staticstruct opa_vnic_vema_port *
vema_get_port(struct opa_vnic_ctrl_port *cport, u8 port_num)
{ struct opa_vnic_vema_port *port = (void *)cport + sizeof(*cport);
if (port_num > cport->num_ports) return NULL;
return port + (port_num - 1);
}
/** * opa_vnic_vema_send_trap -- This function sends a trap to the EM * @adapter: pointer to vnic adapter * @data: pointer to trap data filled by calling function * @lid: issuers lid (encap_slid from vesw_port_info) * * This function is called from the VNIC driver to send a trap if there * is somethng the EM should be notified about. These events currently * are * 1) UNICAST INTERFACE MACADDRESS changes * 2) MULTICAST INTERFACE MACADDRESS changes * 3) ETHERNET LINK STATUS changes * While allocating the send mad the remote site qpn used is 1 * as this is the well known QP. *
*/ void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter, struct __opa_veswport_trap *data, u32 lid)
{ struct opa_vnic_ctrl_port *cport = adapter->cport; struct ib_mad_send_buf *send_buf; struct opa_vnic_vema_port *port; struct ib_device *ibp; struct opa_vnic_vema_mad_trap *trap_mad; struct opa_class_port_info *class; struct rdma_ah_attr ah_attr; struct ib_ah *ah; struct opa_veswport_trap *trap;
u32 trap_lid;
u16 pkey_idx;
if (!cport) goto err_exit;
ibp = cport->ibdev;
port = vema_get_port(cport, data->opaportnum); if (!port || !port->mad_agent) goto err_exit;
class = &port->class_port_info; /* Set up address handle */
memset(&ah_attr, 0, sizeof(ah_attr));
ah_attr.type = rdma_ah_find_type(ibp, port->port_num);
rdma_ah_set_sl(&ah_attr,
GET_TRAP_SL_FROM_CLASS_PORT_INFO(class->trap_sl_rsvd));
rdma_ah_set_port_num(&ah_attr, port->port_num);
trap_lid = be32_to_cpu(class->trap_lid); /* * check for trap lid validity, must not be zero * The trap sink could change after we fashion the MAD but since traps * are not guaranteed we won't use a lock as anyway the change will take * place even with locking.
*/ if (!trap_lid) {
c_err("%s: Invalid dlid\n", __func__); goto err_exit;
}
/** * vema_unregister -- Unregisters agent * @cport: pointer to control port * * This deletes the registration by VEMA for MADs
*/ staticvoid vema_unregister(struct opa_vnic_ctrl_port *cport)
{ struct opa_vnic_adapter *adapter; unsignedlong index; int i;
for (i = 1; i <= cport->num_ports; i++) { struct opa_vnic_vema_port *port = vema_get_port(cport, i);
if (!port->mad_agent) continue;
/* Lock ensures no MAD is being processed */
mutex_lock(&port->lock);
xa_for_each(&port->vports, index, adapter)
opa_vnic_rem_netdev(adapter);
mutex_unlock(&port->lock);
/** * vema_register -- Registers agent * @cport: pointer to control port * * This function registers the handlers for the VEMA MADs * * Return: returns 0 on success. non zero otherwise
*/ staticint vema_register(struct opa_vnic_ctrl_port *cport)
{ struct ib_mad_reg_req reg_req = {
.mgmt_class = OPA_MGMT_CLASS_INTEL_EMA,
.mgmt_class_version = OPA_MGMT_BASE_VERSION,
.oui = { INTEL_OUI_1, INTEL_OUI_2, INTEL_OUI_3 }
}; int i;
/* register ib event handler and mad agent for each port on dev */ for (i = 1; i <= cport->num_ports; i++) { struct opa_vnic_vema_port *port = vema_get_port(cport, i); int ret;
xa_init(&port->vports);
mutex_init(&port->lock);
port->mad_agent = ib_register_mad_agent(cport->ibdev, i,
IB_QPT_GSI, ®_req,
IB_MGMT_RMPP_VERSION,
vema_send, vema_recv,
port, 0); if (IS_ERR(port->mad_agent)) {
ret = PTR_ERR(port->mad_agent);
port->mad_agent = NULL;
mutex_destroy(&port->lock);
vema_unregister(cport); return ret;
}
}
return 0;
}
/** * opa_vnic_ctrl_config_dev -- This function sends a trap to the EM * by way of ib_modify_port to indicate support for ethernet on the * fabric. * @cport: pointer to control port * @en: enable or disable ethernet on fabric support
*/ staticvoid opa_vnic_ctrl_config_dev(struct opa_vnic_ctrl_port *cport, bool en)
{ struct ib_port_modify pm = { 0 }; int i;
if (en)
pm.set_port_cap_mask = OPA_CAP_MASK3_IsEthOnFabricSupported; else
pm.clr_port_cap_mask = OPA_CAP_MASK3_IsEthOnFabricSupported;
for (i = 1; i <= cport->num_ports; i++)
ib_modify_port(cport->ibdev, i, IB_PORT_OPA_MASK_CHG, &pm);
}
/** * opa_vnic_vema_add_one -- Handle new ib device * @device: ib device pointer * * Allocate the vnic control port and initialize it.
*/ staticint opa_vnic_vema_add_one(struct ib_device *device)
{ struct opa_vnic_ctrl_port *cport; int rc, size = sizeof(*cport);
if (!rdma_cap_opa_vnic(device)) return -EOPNOTSUPP;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.