Skip to content

Commit 5d9157a

Browse files
Dean Luickgregkh
authored andcommitted
staging/rdma/hfi1: Read EFI variable for device description
Read an EFI variable for the device description. Create the infrastructure for additional variable reads. Reviewed-by: Easwar Hariharan <easwar.hariharan@intel.com> Signed-off-by: Dean Luick <dean.luick@intel.com> Signed-off-by: Jubin John <jubin.john@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 995deaf commit 5d9157a

4 files changed

Lines changed: 260 additions & 9 deletions

File tree

‎drivers/staging/rdma/hfi1/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o
99

10-
hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o eprom.o file_ops.o firmware.o \
10+
hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o efivar.o eprom.o file_ops.o firmware.o \
1111
init.o intr.o keys.o mad.o mmap.o mr.o pcie.o pio.o pio_copy.o \
1212
qp.o qsfp.o rc.o ruc.o sdma.o srq.o sysfs.o trace.o twsi.o \
1313
uc.o ud.o user_pages.o user_sdma.o verbs_mcast.o verbs.o

‎drivers/staging/rdma/hfi1/chip.c‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "pio.h"
6464
#include "sdma.h"
6565
#include "eprom.h"
66+
#include "efivar.h"
6667

6768
#define NUM_IB_PORTS 1
6869

@@ -10461,6 +10462,32 @@ static void asic_should_init(struct hfi1_devdata *dd)
1046110462
spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1046210463
}
1046310464

10465+
/*
10466+
* Set dd->boardname. Use a generic name if a name is not returned from
10467+
* EFI variable space.
10468+
*
10469+
* Return 0 on success, -ENOMEM if space could not be allocated.
10470+
*/
10471+
static int obtain_boardname(struct hfi1_devdata *dd)
10472+
{
10473+
/* generic board description */
10474+
const char generic[] =
10475+
"Intel Omni-Path Host Fabric Interface Adapter 100 Series";
10476+
unsigned long size;
10477+
int ret;
10478+
10479+
ret = read_hfi1_efi_var(dd, "description", &size,
10480+
(void **)&dd->boardname);
10481+
if (ret) {
10482+
dd_dev_err(dd, "Board description not found\n");
10483+
/* use generic description */
10484+
dd->boardname = kstrdup(generic, GFP_KERNEL);
10485+
if (!dd->boardname)
10486+
return -ENOMEM;
10487+
}
10488+
return 0;
10489+
}
10490+
1046410491
/**
1046510492
* Allocate and initialize the device structure for the hfi.
1046610493
* @dev: the pci_dev for hfi1_ib device
@@ -10658,18 +10685,13 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
1065810685

1065910686
parse_platform_config(dd);
1066010687

10661-
/* add board names as they are defined */
10662-
dd->boardname = kmalloc(64, GFP_KERNEL);
10663-
if (!dd->boardname)
10688+
ret = obtain_boardname(dd);
10689+
if (ret)
1066410690
goto bail_cleanup;
10665-
snprintf(dd->boardname, 64, "Board ID 0x%llx",
10666-
dd->revision >> CCE_REVISION_BOARD_ID_LOWER_NIBBLE_SHIFT
10667-
& CCE_REVISION_BOARD_ID_LOWER_NIBBLE_MASK);
1066810691

1066910692
snprintf(dd->boardversion, BOARD_VERS_MAX,
10670-
"ChipABI %u.%u, %s, ChipRev %u.%u, SW Compat %llu\n",
10693+
"ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
1067110694
HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
10672-
dd->boardname,
1067310695
(u32)dd->majrev,
1067410696
(u32)dd->minrev,
1067510697
(dd->revision >> CCE_REVISION_SW_SHIFT)

‎drivers/staging/rdma/hfi1/efivar.c‎

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
*
3+
* This file is provided under a dual BSD/GPLv2 license. When using or
4+
* redistributing this file, you may do so under either license.
5+
*
6+
* GPL LICENSE SUMMARY
7+
*
8+
* Copyright(c) 2015 Intel Corporation.
9+
*
10+
* This program is free software; you can redistribute it and/or modify
11+
* it under the terms of version 2 of the GNU General Public License as
12+
* published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful, but
15+
* WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* General Public License for more details.
18+
*
19+
* BSD LICENSE
20+
*
21+
* Copyright(c) 2015 Intel Corporation.
22+
*
23+
* Redistribution and use in source and binary forms, with or without
24+
* modification, are permitted provided that the following conditions
25+
* are met:
26+
*
27+
* - Redistributions of source code must retain the above copyright
28+
* notice, this list of conditions and the following disclaimer.
29+
* - Redistributions in binary form must reproduce the above copyright
30+
* notice, this list of conditions and the following disclaimer in
31+
* the documentation and/or other materials provided with the
32+
* distribution.
33+
* - Neither the name of Intel Corporation nor the names of its
34+
* contributors may be used to endorse or promote products derived
35+
* from this software without specific prior written permission.
36+
*
37+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48+
*
49+
*/
50+
51+
#include "efivar.h"
52+
53+
/* GUID for HFI1 variables in EFI */
54+
#define HFI1_EFIVAR_GUID EFI_GUID(0xc50a953e, 0xa8b2, 0x42a6, \
55+
0xbf, 0x89, 0xd3, 0x33, 0xa6, 0xe9, 0xe6, 0xd4)
56+
/* largest EFI data size we expect */
57+
#define EFI_DATA_SIZE 4096
58+
59+
/*
60+
* Read the named EFI variable. Return the size of the actual data in *size
61+
* and a kmalloc'ed buffer in *return_data. The caller must free the
62+
* data. It is guaranteed that *return_data will be NULL and *size = 0
63+
* if this routine fails.
64+
*
65+
* Return 0 on success, -errno on failure.
66+
*/
67+
static int read_efi_var(const char *name, unsigned long *size,
68+
void **return_data)
69+
{
70+
efi_status_t status;
71+
efi_char16_t *uni_name;
72+
efi_guid_t guid;
73+
unsigned long temp_size;
74+
void *temp_buffer;
75+
void *data;
76+
int i;
77+
int ret;
78+
79+
/* set failure return values */
80+
*size = 0;
81+
*return_data = NULL;
82+
83+
if (!efi_enabled(EFI_RUNTIME_SERVICES))
84+
return -EOPNOTSUPP;
85+
86+
uni_name = kzalloc(sizeof(efi_char16_t) * (strlen(name) + 1),
87+
GFP_KERNEL);
88+
temp_buffer = kzalloc(EFI_DATA_SIZE, GFP_KERNEL);
89+
90+
if (!uni_name || !temp_buffer) {
91+
ret = -ENOMEM;
92+
goto fail;
93+
}
94+
95+
/* input: the size of the buffer */
96+
temp_size = EFI_DATA_SIZE;
97+
98+
/* convert ASCII to unicode - it is a 1:1 mapping */
99+
for (i = 0; name[i]; i++)
100+
uni_name[i] = name[i];
101+
102+
/* need a variable for our GUID */
103+
guid = HFI1_EFIVAR_GUID;
104+
105+
/* call into EFI runtime services */
106+
status = efi.get_variable(
107+
uni_name,
108+
&guid,
109+
NULL,
110+
&temp_size,
111+
temp_buffer);
112+
113+
/*
114+
* It would be nice to call efi_status_to_err() here, but that
115+
* is in the EFIVAR_FS code and may not be compiled in.
116+
* However, even that is insufficient since it does not cover
117+
* EFI_BUFFER_TOO_SMALL which could be an important return.
118+
* For now, just split out succces or not found.
119+
*/
120+
ret = status == EFI_SUCCESS ? 0 :
121+
status == EFI_NOT_FOUND ? -ENOENT :
122+
-EINVAL;
123+
if (ret)
124+
goto fail;
125+
126+
/*
127+
* We have successfully read the EFI variable into our
128+
* temporary buffer. Now allocate a correctly sized
129+
* buffer.
130+
*/
131+
data = kmalloc(temp_size, GFP_KERNEL);
132+
if (!data) {
133+
ret = -ENOMEM;
134+
goto fail;
135+
}
136+
137+
memcpy(data, temp_buffer, temp_size);
138+
*size = temp_size;
139+
*return_data = data;
140+
141+
fail:
142+
kfree(uni_name);
143+
kfree(temp_buffer);
144+
145+
return ret;
146+
}
147+
148+
/*
149+
* Read an HFI1 EFI variable of the form:
150+
* <PCIe address>-<kind>
151+
* Return an kalloc'ed array and size of the data.
152+
*
153+
* Returns 0 on success, -errno on failure.
154+
*/
155+
int read_hfi1_efi_var(struct hfi1_devdata *dd, const char *kind,
156+
unsigned long *size, void **return_data)
157+
{
158+
char name[64];
159+
160+
/* create a common prefix */
161+
snprintf(name, sizeof(name), "%04x:%02x:%02x.%x-%s",
162+
pci_domain_nr(dd->pcidev->bus),
163+
dd->pcidev->bus->number,
164+
PCI_SLOT(dd->pcidev->devfn),
165+
PCI_FUNC(dd->pcidev->devfn),
166+
kind);
167+
168+
return read_efi_var(name, size, return_data);
169+
}

‎drivers/staging/rdma/hfi1/efivar.h‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
*
3+
* This file is provided under a dual BSD/GPLv2 license. When using or
4+
* redistributing this file, you may do so under either license.
5+
*
6+
* GPL LICENSE SUMMARY
7+
*
8+
* Copyright(c) 2015 Intel Corporation.
9+
*
10+
* This program is free software; you can redistribute it and/or modify
11+
* it under the terms of version 2 of the GNU General Public License as
12+
* published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful, but
15+
* WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* General Public License for more details.
18+
*
19+
* BSD LICENSE
20+
*
21+
* Copyright(c) 2015 Intel Corporation.
22+
*
23+
* Redistribution and use in source and binary forms, with or without
24+
* modification, are permitted provided that the following conditions
25+
* are met:
26+
*
27+
* - Redistributions of source code must retain the above copyright
28+
* notice, this list of conditions and the following disclaimer.
29+
* - Redistributions in binary form must reproduce the above copyright
30+
* notice, this list of conditions and the following disclaimer in
31+
* the documentation and/or other materials provided with the
32+
* distribution.
33+
* - Neither the name of Intel Corporation nor the names of its
34+
* contributors may be used to endorse or promote products derived
35+
* from this software without specific prior written permission.
36+
*
37+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48+
*
49+
*/
50+
#ifndef _HFI1_EFIVAR_H
51+
#define _HFI1_EFIVAR_H
52+
53+
#include <linux/efi.h>
54+
55+
#include "hfi.h"
56+
57+
int read_hfi1_efi_var(struct hfi1_devdata *dd, const char *kind,
58+
unsigned long *size, void **return_data);
59+
60+
#endif /* _HFI1_EFIVAR_H */

0 commit comments

Comments
 (0)