Commit 92b2ad31 authored by Federico Vaga's avatar Federico Vaga

style: checkpatch review

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent a8ed2205
......@@ -38,7 +38,7 @@ static int vme_am[SVEC_MAX_DEVICES] = SVEC_DEFAULT_VME_AM;
static unsigned int vme_am_num;
static int vme_size[SVEC_MAX_DEVICES] = SVEC_DEFAULT_VME_SIZE;
static unsigned int vme_size_num;
static int verbose = 0;
static int verbose;
module_param_array(slot, int, &slot_num, S_IRUGO);
MODULE_PARM_DESC(slot, "Slot where SVEC card is installed");
......@@ -59,13 +59,14 @@ MODULE_PARM_DESC(level, "IRQ level");
module_param(verbose, int, S_IRUGO);
MODULE_PARM_DESC(verbose, "Output lots of debugging messages");
/* Maps given VME window using configuration provided through module parameters or sysfs.
Two windows are supported:
- MAP_CR_CSR: CR/CSR space for bootloading the FPGA bitstream and initializing
the VME64x CSR registers
- MAP_REG: the main VME window for the FMC driver. Configured via
module parameters or sysfs.
*/
/* Maps given VME window using configuration provided through
* module parameters or sysfs.
* Two windows are supported:
* - MAP_CR_CSR: CR/CSR space for bootloading the FPGA bitstream and
* initializing the VME64x CSR registers
* - MAP_REG: the main VME window for the FMC driver. Configured via
* module parameters or sysfs.
*/
int svec_map_window(struct svec_dev *svec, enum svec_map_win map_type)
{
......@@ -94,7 +95,8 @@ int svec_map_window(struct svec_dev *svec, enum svec_map_win map_type)
svec->map[map_type] = kzalloc(sizeof(struct vme_mapping), GFP_KERNEL);
if (!svec->map[map_type]) {
dev_err(dev, "Cannot allocate memory for vme_mapping struct\n");
dev_err(dev,
"Cannot allocate memory for vme_mapping struct\n");
return -ENOMEM;
}
......@@ -106,7 +108,8 @@ int svec_map_window(struct svec_dev *svec, enum svec_map_win map_type)
svec->map[map_type]->sizeu = 0;
svec->map[map_type]->sizel = size;
if ((rval = vme_find_mapping(svec->map[map_type], 1)) != 0) {
rval = vme_find_mapping(svec->map[map_type], 1);
if (rval != 0) {
dev_err(dev, "Failed to map window %d: (%d)\n",
(int)map_type, rval);
kfree(svec->map[map_type]);
......@@ -114,10 +117,10 @@ int svec_map_window(struct svec_dev *svec, enum svec_map_win map_type)
return -EINVAL;
}
if(svec->verbose)
dev_info(dev, "%s mapping successful at 0x%p\n",
map_type == MAP_REG ? "register" : "CR/CSR",
svec->map[map_type]->kernel_va);
if (svec->verbose)
dev_info(dev, "%s mapping successful at 0x%p\n",
map_type == MAP_REG ? "register" : "CR/CSR",
svec->map[map_type]->kernel_va);
return 0;
}
......@@ -134,18 +137,20 @@ int svec_unmap_window(struct svec_dev *svec, enum svec_map_win map_type)
dev_err(dev, "Unmap for window %d failed\n", (int)map_type);
return -EINVAL;
}
if(svec->verbose)
dev_info(dev, "Window %d unmapped\n", (int)map_type);
if (svec->verbose)
dev_info(dev, "Window %d unmapped\n", (int)map_type);
kfree(svec->map[map_type]);
svec->map[map_type] = NULL;
return 0;
}
/* Checks if the card responds to a bootloader call in order to determine if
we are talking to a SVEC or not. If it is a SVEC, its Application FPGA is erased!
*/
/*
* Checks if the card responds to a bootloader call in order to determine if
* we are talking to a SVEC or not. If it is a SVEC, its Application FPGA
* is erased!
*/
int svec_check_bootloader_present(struct svec_dev *svec)
{
int rv = 0;
......@@ -167,7 +172,7 @@ int svec_check_bootloader_present(struct svec_dev *svec)
goto fail;
}
fail:
fail:
svec_unmap_window(svec, MAP_CR_CSR);
return rv;
......@@ -191,20 +196,23 @@ int svec_bootloader_unlock(struct svec_dev *svec)
}
addr = svec->map[MAP_CR_CSR]->kernel_va +
SVEC_BASE_LOADER + XLDR_REG_BTRIGR;
SVEC_BASE_LOADER + XLDR_REG_BTRIGR;
/* Magic sequence: unlock bootloader mode, disable application FPGA */
for (i = 0; i < 8; i++)
iowrite32(cpu_to_be32(boot_seq[i]), addr);
if(svec->verbose)
dev_info(dev, "Wrote unlock sequence at %lx\n", (unsigned long)addr);
if (svec->verbose)
dev_info(dev, "Wrote unlock sequence at %lx\n",
(unsigned long)addr);
return 0;
}
/* Checks if the SVEC is in bootloader mode. If true, it implies that the Appliocation
FPGA has no bitstream loaded. */
/**
* Checks if the SVEC is in bootloader mode. If true, it implies that
* the Appliocation FPGA has no bitstream loaded.
*/
int svec_is_bootloader_active(struct svec_dev *svec)
{
struct device *dev = svec->dev;
......@@ -227,9 +235,8 @@ int svec_is_bootloader_active(struct svec_dev *svec)
strncpy(buf, (char *)&idc, 4);
buf[4] = 0;
if (strncmp(buf, "SVEC", 4) == 0) {
if(svec->verbose)
dev_info(dev, "IDCode value %x [%s].\n", idc, buf);
if (svec->verbose)
dev_info(dev, "IDCode value %x [%s].\n", idc, buf);
/* Bootloader active. Unlocked */
return 1;
}
......@@ -244,9 +251,11 @@ static void svec_csr_write(u8 value, void *base, u32 offset)
iowrite32be(value, base + offset);
}
/* Loads the Application FPGA bitstream through the System FPGA bootloader.
Does all necessary VME mappings & checks if the bitstream has not been already
loaded to save time. */
/**
* Loads the Application FPGA bitstream through the System FPGA bootloader.
* Does all necessary VME mappings & checks if the bitstream has not been
* already loaded to save time.
*/
int svec_load_fpga(struct svec_dev *svec, const void *blob, int size)
{
struct device *dev = svec->dev;
......@@ -266,12 +275,12 @@ int svec_load_fpga(struct svec_dev *svec, const void *blob, int size)
/* Hash firmware bitstream */
fw_hash = jhash(blob, size, 0);
if (fw_hash == svec->fw_hash) {
if(svec->verbose)
dev_info(svec->dev,
"card already programmed with bitstream with hash 0x%x\n",
fw_hash);
set_bit(SVEC_FLAG_AFPGA_PROGRAMMED, &svec->flags);
if (svec->verbose)
dev_info(svec->dev,
"card already programmed with bitstream with hash 0x%x\n",
fw_hash);
set_bit(SVEC_FLAG_AFPGA_PROGRAMMED, &svec->flags);
return 0;
}
......@@ -341,8 +350,8 @@ int svec_load_fpga(struct svec_dev *svec, const void *blob, int size)
return -EINVAL;
}
if(svec->verbose)
dev_info(dev, "Bitstream loaded, status: OK\n");
if (svec->verbose)
dev_info(dev, "Bitstream loaded, status: OK\n");
/* give the VME bus control to App FPGA */
iowrite32(cpu_to_be32(XLDR_CSR_EXIT), loader_addr + XLDR_REG_CSR);
......@@ -352,8 +361,11 @@ int svec_load_fpga(struct svec_dev *svec, const void *blob, int size)
set_bit(SVEC_FLAG_AFPGA_PROGRAMMED, &svec->flags);
/* after a successful reprogram, save the hash so that the future call can
return earlier if requested to load the same bitstream */
/*
* after a successful reprogram, save the hash so that the
* future call can return earlier if requested to load the
* same bitstream
*/
svec->fw_hash = fw_hash;
return 0;
......@@ -372,8 +384,8 @@ static int svec_remove(struct device *pdev, unsigned int ndev)
svec_unmap_window(svec, MAP_REG);
svec_remove_sysfs_files(svec);
if(svec->verbose)
dev_info(pdev, "removed\n");
if (svec->verbose)
dev_info(pdev, "removed\n");
kfree(svec);
......@@ -398,9 +410,9 @@ int svec_load_fpga_file(struct svec_dev *svec, const char *name)
return err;
}
if(svec->verbose)
dev_info(dev, "Got file \"%s\", %zi (0x%zx) bytes\n",
name, fw->size, fw->size);
if (svec->verbose)
dev_info(dev, "Got file \"%s\", %zi (0x%zx) bytes\n",
name, fw->size, fw->size);
err = svec_load_fpga(svec, (uint32_t *) fw->data, fw->size);
release_firmware(fw);
......@@ -408,7 +420,10 @@ int svec_load_fpga_file(struct svec_dev *svec, const char *name)
return err;
}
/* Checks if a SVEC with a valid Application FPGA gateware is present at a given slot. */
/**
* Checks if a SVEC with a valid Application FPGA gateware is present
* at a given slot.
*/
int svec_is_present(struct svec_dev *svec)
{
struct device *dev = svec->dev;
......@@ -416,9 +431,8 @@ int svec_is_present(struct svec_dev *svec)
void *addr;
/* Check for bootloader */
if (svec_is_bootloader_active(svec)) {
if (svec_is_bootloader_active(svec))
return 1;
}
/* Ok, maybe there is a svec, but bootloader is not active.
In such case, a CR/CSR with a valid manufacturer ID should exist */
......@@ -430,8 +444,8 @@ int svec_is_present(struct svec_dev *svec)
idc += be32_to_cpu(ioread32(addr + 8));
if (idc == SVEC_VENDOR_ID) {
if(svec->verbose)
dev_info(dev, "vendor ID is 0x%08x\n", idc);
if (svec->verbose)
dev_info(dev, "vendor ID is 0x%08x\n", idc);
return 1;
}
......@@ -442,7 +456,10 @@ int svec_is_present(struct svec_dev *svec)
return 0;
}
/* Sets up the VME64x core to respond to a address range and issue interrupts to given vector. */
/*
* Sets up the VME64x core to respond to a address range and
* issue interrupts to given vector.
*/
int svec_setup_csr(struct svec_dev *svec)
{
......@@ -453,7 +470,7 @@ int svec_setup_csr(struct svec_dev *svec)
/* don't try to set up CSRs of an empty AFPGA */
if (!test_bit(SVEC_FLAG_AFPGA_PROGRAMMED, &svec->flags))
return 0;
return 0;
if (!svec->map[MAP_CR_CSR])
rv = svec_map_window(svec, MAP_CR_CSR);
......@@ -483,7 +500,8 @@ int svec_setup_csr(struct svec_dev *svec)
svec_csr_write(svec->cfg_cur.interrupt_level, base, INT_LEVEL);
switch (svec->cfg_cur.vme_am) {
/* choose the function to use: A32 is 0, A24 is 1. The rest is purposedly disabled. */
/* choose the function to use: A32 is 0, A24 is 1.
The rest is purposedly disabled. */
case VME_A32_USER_DATA_SCT:
func = 0;
break;
......@@ -496,13 +514,16 @@ int svec_setup_csr(struct svec_dev *svec)
memset(ader, 0, sizeof(ader));
/* Below is a hack to keep the VME core function disabling work on bitstreams
containing a buggy VME core (commit b2fc3ce7): set bit 0 (XAM_MODE) to 1
to disable given function (because neither function 0 nor 1 have anything
in their extended capability sets, setting XAM_MODE = 1 effectively disables
the function. */
/*
* Below is a hack to keep the VME core function disabling
* work on bitstreams containing a buggy VME core
* (commit b2fc3ce7): set bit 0 (XAM_MODE) to 1 to disable
* given function (because neither function 0 nor 1 have anything
* in their extended capability sets, setting XAM_MODE = 1
* effectively disables the function.
*/
ader[0][3] = 1;
ader[0][3] = 1;
ader[1][3] = 1;
/* do address relocation for FUN0/1 */
......@@ -511,7 +532,8 @@ int svec_setup_csr(struct svec_dev *svec)
ader[func][2] = (svec->cfg_cur.vme_base >> 8) & 0xFF;
ader[func][3] = (svec->cfg_cur.vme_am & 0x3F) << 2;
/* DFSR and XAM are zero. Program both functions, but only one will be enabled. */
/* DFSR and XAM are zero. Program both functions,
but only one will be enabled. */
svec_csr_write(ader[0][0], base, FUN0ADER);
svec_csr_write(ader[0][1], base, FUN0ADER + 4);
svec_csr_write(ader[0][2], base, FUN0ADER + 8);
......@@ -525,28 +547,32 @@ int svec_setup_csr(struct svec_dev *svec)
/* enable module, hence make FUN0/1 available */
svec_csr_write(ENABLE_CORE, base, BIT_SET_REG);
exit_reconf:
exit_reconf:
/* unmap the CSR window after configuring the card, it's no longer necessary */
/* unmap the CSR window after configuring the card, it's
no longer necessary */
svec_unmap_window(svec, MAP_CR_CSR);
return rv;
}
/* Performs some checks on VME window address/size/am and interrupts configuration.
Note that the checks are not rock solid (no checking for overlapping VME windows
for instance), so it's still possible for a determinate user to screw something up. */
/**
* Performs some checks on VME window address/size/am and interrupts
* configuration. Note that the checks are not rock solid (no checking
* for overlapping VME windows for instance), so it's still possible for
* a determinate user to screw something up.
*/
int svec_validate_configuration(struct device *pdev, struct svec_config *cfg)
{
uint32_t addr_mask, start_masked, end_masked;
uint32_t max_size;
/* no base address assigned? silently return. */
if (cfg->vme_base == (uint32_t) - 1)
if (cfg->vme_base == (uint32_t) -1)
return 0;
if (cfg->interrupt_vector == (uint32_t) - 1)
if (cfg->interrupt_vector == (uint32_t) -1)
return 0;
switch (cfg->vme_am) {
case VME_A32_USER_DATA_SCT:
addr_mask = 0xff000000;
......@@ -563,12 +589,9 @@ int svec_validate_configuration(struct device *pdev, struct svec_config *cfg)
}
if (cfg->vme_am == VME_A24_USER_DATA_SCT &&
cfg->vme_base >= 0xf00000)
{
cfg->vme_base >= 0xf00000) {
dev_err(pdev,
"VME base address for A24 mode must not be >= 0xf00000 due to "
"addressing conflict with the Tsi148 VME bridge. Please change "
"your card's configuration.\n");
"VME base address for A24 mode must not be >= 0xf00000 due to addressing conflict with the Tsi148 VME bridge. Please change your card's configuration.\n");
return 0;
}
......@@ -627,22 +650,26 @@ static void svec_prepare_description(struct svec_dev *svec)
dev_info(svec->dev, "%s\n", svec->description);
}
/* Reconfigures everything after the VME configuration has been changed. Called during
probing of the card (if sufficient VME config is given via module parameters) or when the
configuration is assigned through sysfs. Reconfiguration implies re-loading the FMCs. */
/**
* Reconfigures everything after the VME configuration has been changed.
* Called during probing of the card (if sufficient VME config is given
* via module parameters) or when the configuration is assigned through
* sysfs. Reconfiguration implies re-loading the FMCs.
*/
int svec_reconfigure(struct svec_dev *svec)
{
int error;
/* no valid VME configuration? Silently return (it has to be done at some point via sysfs) */
/* no valid VME configuration? Silently return (it has to be done
at some point via sysfs) */
if (!svec->cfg_cur.configured)
return 0;
/* FMCs loaded: remove before reconfiguring VME */
if (test_bit(SVEC_FLAG_FMCS_REGISTERED, &svec->flags)) {
if(svec->verbose)
dev_info(svec->dev,
"re-registering FMCs due to sysfs-triggered card reconfiguration\n");
if (svec->verbose)
dev_info(svec->dev,
"re-registering FMCs due to sysfs-triggered card reconfiguration\n");
svec_fmc_destroy(svec);
clear_bit(SVEC_FLAG_FMCS_REGISTERED, &svec->flags);
}
......@@ -673,7 +700,7 @@ int svec_reconfigure(struct svec_dev *svec)
}
return 0;
failed_unmap:
failed_unmap:
svec_unmap_window(svec, MAP_REG);
return error;
}
......@@ -738,9 +765,7 @@ static int svec_probe(struct device *pdev, unsigned int ndev)
/* see if we are really talking to a SVEC */
if (svec_check_bootloader_present(svec) < 0) {
dev_err(pdev,
"ERROR: The SVEC expected in slot %d is not responding, "
"the mezzanines installed on it will not be visible in the"
"system. Please check if the card is correctly installed.\n",
"ERROR: The SVEC expected in slot %d is not responding, the mezzanines installed on it will not be visible in the system. Please check if the card is correctly installed.\n",
svec->slot);
error = -ENODEV;
......@@ -748,16 +773,16 @@ static int svec_probe(struct device *pdev, unsigned int ndev)
}
/* Get firmware name */
if (ndev < fw_name_num) {
if (ndev < fw_name_num)
svec->fw_name = fw_name[ndev];
} else {
else
svec->fw_name = svec_fw_name; /* Default value */
}
if(svec->verbose)
dev_info(pdev, "using '%s' golden bitstream.", svec->fw_name);
if (svec->verbose)
dev_info(pdev, "using '%s' golden bitstream.",
svec->fw_name);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
name = pdev->bus_id;
#else
name = dev_name(pdev);
......@@ -791,7 +816,7 @@ static struct vme_driver svec_driver = {
.remove = svec_remove,
.driver = {
.name = KBUILD_MODNAME,
},
},
};
static int __init svec_init(void)
......@@ -818,8 +843,7 @@ static int __init svec_init(void)
error |= (fw_name_num && fw_name_num != slot_num);
if (error) {
pr_err
("%s: The number of vme_base/vme_am/vme_size/level/vector/fw_name/use_vic/use_fmc parameters must be zero or equal to the number of cards.\n",
pr_err("%s: The number of vme_base/vme_am/vme_size/level/vector/fw_name/use_vic/use_fmc parameters must be zero or equal to the number of cards.\n",
__func__);
return -EINVAL;
}
......
......@@ -60,8 +60,8 @@ static int svec_reprogram(struct fmc_device *fmc, struct fmc_driver *drv,
return -ESRCH; /* the caller may accept this */
}
if(svec->verbose)
dev_info(fmc->hwdev, "reprogramming with %s\n", gw);
if (svec->verbose)
dev_info(fmc->hwdev, "reprogramming with %s\n", gw);
ret = request_firmware(&fw, gw, dev);
if (ret < 0) {
dev_warn(dev, "request firmware \"%s\": error %i\n", gw, ret);
......@@ -83,7 +83,7 @@ static int svec_reprogram(struct fmc_device *fmc, struct fmc_driver *drv,
fmc->flags |= FMC_DEVICE_HAS_CUSTOM;
out:
out:
release_firmware(fw);
if (ret < 0)
dev_err(dev, "svec reprogram failed while loading %s\n", gw);
......@@ -113,7 +113,7 @@ static int svec_write_ee(struct fmc_device *fmc, int pos,
{
if (!(fmc->flags & FMC_DEVICE_HAS_GOLDEN))
return -ENOTSUPP;
return svec_eeprom_write(fmc, pos, data, len);
}
......@@ -142,7 +142,8 @@ static int check_golden(struct fmc_device *fmc)
dev_err(svec->dev, "Bad SDB magic: 0x%08x\n", magic);
return -ENODEV;
}
if ((ret = fmc_scan_sdb_tree(fmc, 0x0)) < 0)
ret = fmc_scan_sdb_tree(fmc, 0x0);
if (ret < 0)
return -ENODEV;
vendor = fmc_readl(fmc, 0x5c);
......@@ -213,7 +214,7 @@ int svec_fmc_prepare(struct svec_dev *svec, unsigned int fmc_slot)
}
fmc->flags |= FMC_DEVICE_HAS_GOLDEN;
ret = svec_i2c_init(fmc);
if (ret) {
dev_err(svec->dev, "Error %d on svec i2c init", ret);
......@@ -222,10 +223,10 @@ int svec_fmc_prepare(struct svec_dev *svec, unsigned int fmc_slot)
}
svec->fmcs[fmc_slot] = fmc;
if(svec->verbose)
dev_info(svec->dev, "ready to create fmc device_id 0x%x\n",
fmc->device_id);
if (svec->verbose)
dev_info(svec->dev, "ready to create fmc device_id 0x%x\n",
fmc->device_id);
return ret;
}
......@@ -238,7 +239,6 @@ int svec_fmc_create(struct svec_dev *svec)
/* fmc structures filling */
for (i = 0; i < svec->fmcs_n; i++) {
error = svec_fmc_prepare(svec, i);
if (error)
goto failed;
}
......@@ -252,16 +252,14 @@ int svec_fmc_create(struct svec_dev *svec)
/* FIXME: how do we retrieve the actual number of registered
* devices?
*/
if(svec->verbose)
dev_info(svec->dev, "fmc devices registered\n");
if (svec->verbose)
dev_info(svec->dev, "fmc devices registered\n");
return 0;
failed:
failed:
for (i = 0; i < svec->fmcs_n; i++)
if (svec->fmcs[i])
kfree(svec->fmcs[i]);
kfree(svec->fmcs[i]);
/* FIXME: free fmc allocations. */
return error;
......@@ -280,7 +278,8 @@ void svec_fmc_destroy(struct svec_dev *svec)
svec->vic, svec->flags);
memset(svec->fmcs, 0, sizeof(struct fmc_devices *) * SVEC_N_SLOTS);
if(svec->verbose)
dev_info(svec->dev, "%d fmc devices unregistered\n", svec->fmcs_n);
if (svec->verbose)
dev_info(svec->dev, "%d fmc devices unregistered\n",
svec->fmcs_n);
}
......@@ -25,21 +25,30 @@ static int svec_irq_handler(void *data)
svec->irq_count++;
/* just in case we had an IRQ while messing around with the VIC registers/fmc_handlers */
/*
* just in case we had an IRQ while messing around with the
* VIC registers/fmc_handlers
*/
spin_lock_irqsave(&svec->irq_lock, flags);
if (svec->vic)
rv = svec_vic_irq_dispatch(svec);
else {
/* shared irq mode: call all handlers until one of them has dealt with the interrupt */
/*
* shared irq mode: call all handlers until one of them
* has dealt with the interrupt
*/
for (i = 0; i < SVEC_N_SLOTS; i++) {
irq_handler_t handler = svec->fmc_handlers[i];
/* Call all handlers even if the current one returned IRQ_HANDLED. The SVEC
VME Core IRQ is edge-sensitive, doing otherwise could result in missed irqs! */
if (handler)
/*
* Call all handlers even if the current one
* returned IRQ_HANDLED. The SVEC VME Core IRQ
* is edge-sensitive, doing otherwise could
* result in missed irqs!
*/
if (handler)
handler(i, svec->fmcs[i]);
}
}
......@@ -59,7 +68,10 @@ int svec_irq_request(struct fmc_device *fmc, irq_handler_t handler,
struct svec_dev *svec = (struct svec_dev *)fmc->carrier_data;
int rv = 0;
/* Depending on IRQF_SHARED flag, choose between a VIC and shared IRQ mode */
/*
* Depending on IRQF_SHARED flag, choose between a VIC and
* shared IRQ mode
*/
if (!flags)
rv = svec_vic_irq_request(svec, fmc, fmc->irq, handler);
else if (flags & IRQF_SHARED) {
......@@ -69,7 +81,10 @@ int svec_irq_request(struct fmc_device *fmc, irq_handler_t handler,
} else
return -EINVAL;
/* register the master VME handler the first time somebody requests an interrupt */
/*
* register the master VME handler the first time somebody
* requests an interrupt
*/
if (!rv && !test_bit(SVEC_FLAG_IRQS_REQUESTED, &svec->flags)) {
rv = vme_request_irq(svec->cfg_cur.interrupt_vector,
......@@ -87,6 +102,7 @@ int svec_irq_request(struct fmc_device *fmc, irq_handler_t handler,
void svec_irq_ack(struct fmc_device *fmc)
{
struct svec_dev *svec = (struct svec_dev *)fmc->carrier_data;
if (svec->vic)
svec_vic_irq_ack(svec, fmc->irq);
}
......@@ -108,7 +124,10 @@ int svec_irq_free(struct fmc_device *fmc)
spin_unlock(&svec->irq_lock);
}
/* shared IRQ mode: disable VME interrupt when freeing last FMC handler */
/*
* shared IRQ mode: disable VME interrupt when freeing last
* FMC handler
*/
if (!svec->vic && !svec->fmc_handlers[0] && !svec->fmc_handlers[1]) {
rv = vme_free_irq(svec->current_vector);
if (rv < 0)
......
......@@ -29,48 +29,49 @@
#define FW_CMD_RESET 0
#define FW_CMD_PROGRAM 1
static int svec_fw_cmd_reset (struct svec_dev * card)
static int svec_fw_cmd_reset(struct svec_dev *card)
{
int err = 0;
if (test_bit (SVEC_FLAG_FMCS_REGISTERED, &card->flags))
svec_fmc_destroy (card);
if (test_bit(SVEC_FLAG_FMCS_REGISTERED, &card->flags))
svec_fmc_destroy(card);
if (!card->map[MAP_CR_CSR])
err = svec_map_window (card, MAP_CR_CSR);
err = svec_map_window(card, MAP_CR_CSR);
if(err < 0)
if (err < 0)
return err;
svec_bootloader_unlock (card);
svec_bootloader_unlock(card);
if (!svec_is_bootloader_active (card))
if (!svec_is_bootloader_active(card))
return -ENODEV;
if (card->fw_buffer)
kfree (card->fw_buffer);
kfree(card->fw_buffer);
card->fw_buffer = vmalloc (SVEC_MAX_GATEWARE_SIZE);
card->fw_buffer = vmalloc(SVEC_MAX_GATEWARE_SIZE);
card->fw_length = 0;
card->fw_hash = 0xffffffff;
return 0;
}
static int svec_fw_cmd_program (struct svec_dev * card)
static int svec_fw_cmd_program(struct svec_dev *card)
{
int err;
if (!card->fw_buffer || !card->fw_length)
return -EINVAL;
return -EINVAL;
err = svec_load_fpga (card, card->fw_buffer, card->fw_length);
vfree (card->fw_buffer);
err = svec_load_fpga(card, card->fw_buffer, card->fw_length);
vfree(card->fw_buffer);
card->fw_buffer = NULL;
card->fw_length = 0;
if (err < 0)
return err;
svec_reconfigure (card);
svec_reconfigure(card);
return 0;
}
......@@ -110,19 +111,17 @@ ATTR_STORE_CALLBACK(firmware_name)
ATTR_STORE_CALLBACK(firmware_cmd)
{
int cmd;
struct svec_dev *card = dev_get_drvdata(pdev);
if (sscanf(buf, "%i", &cmd) != 1)
return -EINVAL;
switch(cmd)
{
case FW_CMD_RESET:
return svec_fw_cmd_reset (card);
case FW_CMD_PROGRAM:
return svec_fw_cmd_program (card);
default:
switch (cmd) {
case FW_CMD_RESET:
return svec_fw_cmd_reset(card);
case FW_CMD_PROGRAM:
return svec_fw_cmd_program(card);
default:
return -EINVAL;
}
......@@ -134,16 +133,15 @@ ATTR_STORE_CALLBACK(firmware_blob)
struct svec_dev *card = dev_get_drvdata(pdev);
if (!card->fw_buffer)
return -EAGAIN;
return -EAGAIN;
if (card->fw_length + count - 1 >= SVEC_MAX_GATEWARE_SIZE)
return -EINVAL;
return -EINVAL;
memcpy (card->fw_buffer + card->fw_length, buf, count);
memcpy(card->fw_buffer + card->fw_length, buf, count);
card->fw_length += count;
return count;
}
ATTR_SHOW_CALLBACK(dummy_attr)
......@@ -154,6 +152,7 @@ ATTR_SHOW_CALLBACK(dummy_attr)
ATTR_SHOW_CALLBACK(interrupt_vector)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "0x%x\n",
card->cfg_cur.interrupt_vector);
}
......@@ -161,13 +160,13 @@ ATTR_SHOW_CALLBACK(interrupt_vector)
ATTR_SHOW_CALLBACK(interrupt_level)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "%d\n", card->cfg_cur.interrupt_level);
}
ATTR_STORE_CALLBACK(interrupt_level)
{
int lvl;
struct svec_dev *card = dev_get_drvdata(pdev);
if (sscanf(buf, "%i", &lvl) != 1)
......@@ -182,7 +181,6 @@ ATTR_STORE_CALLBACK(interrupt_level)
ATTR_STORE_CALLBACK(interrupt_vector)
{
int vec;
struct svec_dev *card = dev_get_drvdata(pdev);
if (sscanf(buf, "%i", &vec) != 1)
......@@ -197,13 +195,13 @@ ATTR_STORE_CALLBACK(interrupt_vector)
ATTR_SHOW_CALLBACK(vme_am)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "0x%x\n", card->cfg_cur.vme_am);
}
ATTR_STORE_CALLBACK(vme_am)
{
int am;
struct svec_dev *card = dev_get_drvdata(pdev);
if (sscanf(buf, "%i", &am) != 1)
......@@ -216,6 +214,7 @@ ATTR_STORE_CALLBACK(vme_am)
ATTR_SHOW_CALLBACK(vme_base)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "0x%x\n", card->cfg_cur.vme_base);
}
......@@ -235,6 +234,7 @@ ATTR_STORE_CALLBACK(vme_base)
ATTR_SHOW_CALLBACK(vme_size)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "0x%x\n", card->cfg_cur.vme_size);
}
......@@ -254,6 +254,7 @@ ATTR_STORE_CALLBACK(vme_size)
ATTR_SHOW_CALLBACK(vme_addr)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "0x%x\n", card->vme_raw_addr);
}
......@@ -298,13 +299,13 @@ static int __next_token(char **str, char *buf, int buf_length)
char *p = *str, *tok;
int len;
while(isspace (*p))
while (isspace(*p))
p++;
if(*p == 0)
if (*p == 0)
return 0;
tok = p;
while(*p && !isspace(*p))
while (*p && !isspace(*p))
p++;
len = min(p - tok + 1, buf_length - 1);
......@@ -321,12 +322,11 @@ ATTR_STORE_CALLBACK(vme_data)
uint32_t data;
uint32_t addr = card->vme_raw_addr;
char *args = (char *) buf, token[16];
if (!card->cfg_cur.configured)
return -EAGAIN;
while (__next_token (&args, token, sizeof(token)))
{
while (__next_token(&args, token, sizeof(token))) {
if (sscanf(token, "%i", &data) != 1)
return -EINVAL;
......@@ -340,6 +340,7 @@ ATTR_STORE_CALLBACK(vme_data)
ATTR_SHOW_CALLBACK(use_vic)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "%d", card->cfg_cur.use_vic);
}
......@@ -363,13 +364,13 @@ ATTR_STORE_CALLBACK(use_vic)
ATTR_SHOW_CALLBACK(use_fmc)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "%d\n", card->cfg_cur.use_fmc);
}
ATTR_STORE_CALLBACK(use_fmc)
{
int enabled;
struct svec_dev *card = dev_get_drvdata(pdev);
if (sscanf(buf, "%i", &enabled) != 1)
......@@ -385,6 +386,7 @@ ATTR_STORE_CALLBACK(use_fmc)
ATTR_SHOW_CALLBACK(configured)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "%d\n", card->cfg_cur.configured);
}
......@@ -409,6 +411,7 @@ ATTR_STORE_CALLBACK(configured)
ATTR_SHOW_CALLBACK(slot)
{
struct svec_dev *card = dev_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE, "%d\n", card->slot);
}
......@@ -428,8 +431,8 @@ static DEVICE_ATTR(firmware_blob,
the userspace tools. */
static DEVICE_ATTR(slot, S_IRUGO, svec_show_slot, NULL);
/* Standard VME configuration attributes. Committed in atomic way by writing 1 to
1 to 'configured' attribute. */
/* Standard VME configuration attributes. Committed in atomic way by
writing 1 to 1 to 'configured' attribute. */
static DEVICE_ATTR(interrupt_vector,
S_IWUSR | S_IRUGO,
svec_show_interrupt_vector, svec_store_interrupt_vector);
......@@ -448,20 +451,22 @@ static DEVICE_ATTR(vme_am,
S_IWUSR | S_IRUGO, svec_show_vme_am, svec_store_vme_am);
/*
Enables support for the Vectored Interrupt Controller (VIC).
Enables support for the Vectored Interrupt Controller (VIC).
By default, the VIC is enabled and enumerated through SDB the first
time the FMC driver requests an interrupt. If no VIC is found, the driver
falls back to shared IRQ mode. This attribute is only to be used in exceptional
situations, where even attempting to look for the VIC may screw the card. */
falls back to shared IRQ mode. This attribute is only to be used in
exceptional situations, where even attempting to look for the VIC may
screw the card.
*/
static DEVICE_ATTR(use_vic,
S_IWUSR | S_IRUGO, svec_show_use_vic, svec_store_use_vic);
/*
Enables registration of the FMCs after checking their FRU information.
Enabled by default, you may want to disable it for debugging purposes (programming
EEPROMs and/or raw VME access)
*/
* Enables registration of the FMCs after checking their FRU information.
* Enabled by default, you may want to disable it for debugging purposes
* (programming EEPROMs and/or raw VME access)
*/
static DEVICE_ATTR(use_fmc,
S_IWUSR | S_IRUGO, svec_show_use_fmc, svec_store_use_fmc);
......
......@@ -5,7 +5,7 @@
* Released according to the GNU GPL, version 2 or any later version
*
* Driver for SVEC (Simple VME FMC carrier) board.
* VIC (Vectored Interrupt Controller) support code.
* VIC (Vectored Interrupt Controller) support code.
*/
#include <linux/interrupt.h>
......@@ -62,10 +62,10 @@ static int svec_vic_init(struct svec_dev *svec, struct fmc_device *fmc)
signed long vic_base;
struct vic_irq_controller *vic;
/* Try to look up the VIC in the SDB tree - note that IRQs shall be requested after the
FMC driver has scanned the SDB tree */
vic_base =
fmc_find_sdb_device(fmc->sdb, VIC_SDB_VENDOR, VIC_SDB_DEVICE, NULL);
/* Try to look up the VIC in the SDB tree - note that IRQs shall
be requested after the FMC driver has scanned the SDB tree */
vic_base = fmc_find_sdb_device(fmc->sdb, VIC_SDB_VENDOR,
VIC_SDB_DEVICE, NULL);
if (vic_base < 0) {
dev_err(svec->dev,
......@@ -73,8 +73,8 @@ static int svec_vic_init(struct svec_dev *svec, struct fmc_device *fmc)
return -ENODEV;
}
if(svec->verbose)
dev_info(svec->dev, "Found VIC @ 0x%lx\n", vic_base);
if (svec->verbose)
dev_info(svec->dev, "Found VIC @ 0x%lx\n", vic_base);
vic = kzalloc(sizeof(struct vic_irq_controller), GFP_KERNEL);
if (!vic)
......@@ -87,13 +87,15 @@ static int svec_vic_init(struct svec_dev *svec, struct fmc_device *fmc)
/* disable all IRQs, copy the vector table with pre-defined IRQ ids */
vic_writel(vic, 0xffffffff, VIC_REG_IDR);
for (i = 0; i < VIC_MAX_VECTORS; i++)
vic->vectors[i].saved_id =
vic_readl(vic, VIC_IVT_RAM_BASE + 4 * i);
vic->vectors[i].saved_id = vic_readl(vic,
VIC_IVT_RAM_BASE + 4 * i);
/* configure the VIC output: active high, edge sensitive, pulse width = 1 tick (16 ns) */
/* configure the VIC output:
active high, edge sensitive, pulse width = 1 tick (16 ns),
160 us IRQ retry timer */
vic_writel(vic,
VIC_CTL_ENABLE | VIC_CTL_POL | VIC_CTL_EMU_EDGE |
VIC_CTL_EMU_LEN_W(40000), VIC_REG_CTL); /* 160 us IRQ retry timer */
VIC_CTL_EMU_LEN_W(40000), VIC_REG_CTL);
vic->initialized = 1;
svec->vic = vic;
......@@ -112,15 +114,15 @@ void svec_vic_exit(struct vic_irq_controller *vic)
kfree(vic);
}
irqreturn_t svec_vic_irq_dispatch(struct svec_dev * svec)
irqreturn_t svec_vic_irq_dispatch(struct svec_dev *svec)
{
struct vic_irq_controller *vic = svec->vic;
int index, rv;
struct vector *vec;
do {
/* Our parent IRQ handler: read the index value from the Vector Address Register,
and find matching handler */
/* Our parent IRQ handler: read the index value from
the Vector Address Register, and find matching handler */
index = vic_readl(vic, VIC_REG_VAR) & 0xff;
if (index >= VIC_MAX_VECTORS)
......@@ -131,18 +133,18 @@ irqreturn_t svec_vic_irq_dispatch(struct svec_dev * svec)
goto fail;
rv = vec->handler(vec->saved_id, vec->requestor);
vic_writel(vic, 0, VIC_REG_EOIR); /* ack the irq */
if(rv < 0)
break;
if (rv < 0)
break;
/* check if any IRQ is still pending */
} while (vic_readl(vic, VIC_REG_RISR));
return rv;
fail:
fail:
return 0;
}
......@@ -162,7 +164,8 @@ int svec_vic_irq_request(struct svec_dev *svec, struct fmc_device *fmc,
vic = svec->vic;
for (i = 0; i < VIC_MAX_VECTORS; i++) {
/* find the vector in the stored table, assign handler and enable the line if exists */
/* find the vector in the stored table, assign handler
and enable the line if exists */
if (vic->vectors[i].saved_id == id) {
spin_lock(&svec->vic->vec_lock);
......@@ -173,7 +176,6 @@ int svec_vic_irq_request(struct svec_dev *svec, struct fmc_device *fmc,
spin_unlock(&svec->vic->vec_lock);
return 0;
}
}
......@@ -188,12 +190,12 @@ int svec_vic_irq_request(struct svec_dev *svec, struct fmc_device *fmc,
*/
static inline int vic_handler_count(struct vic_irq_controller *vic)
{
int i, count;
int i, count;
for (i = 0, count = 0; i < VIC_MAX_VECTORS; ++i)
if (vic->vectors[i].handler)
count++;
return count;
for (i = 0, count = 0; i < VIC_MAX_VECTORS; ++i)
if (vic->vectors[i].handler)
count++;
return count;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment