From: Idan Mehalel Date: Mon, 23 Jul 2018 12:24:12 +0000 (+0300) Subject: mstflint: Fix errors found with checkpatch script X-Git-Tag: v4.1.12-124.31.3~316 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b42a987ab18bb239a28caa97c3a68a4533dfed37;p=users%2Fjedix%2Flinux-maple.git mstflint: Fix errors found with checkpatch script Description: Issue: 1471556 Title: Fix compilation isuue Description: Issue: N/A Orabug: 28878697 (cherry picked from commit 8154be122d0f841208b787b728085c565710e0f7 and dfec3c77f977344d234c93704e59a5ca12832ab1) cherry-pick-repo=github.com/Mellanox/mstflint.git Signed-off-by: Brian Maly Conflicts: Files are relocated from 'kernel' directory to 'drivers/net/ethernet/mellanox/mstflint_access' Squashed two commits since the 1st commit has a compilation issue which is fixed by the 2nd commit. Signed-off-by: Qing Huang Reviewed-by: Aron Silverton Signed-off-by: Brian Maly --- diff --git a/drivers/net/ethernet/mellanox/mstflint_access/mst.h b/drivers/net/ethernet/mellanox/mstflint_access/mst.h index d9c737c773615..7ede228674b1b 100644 --- a/drivers/net/ethernet/mellanox/mstflint_access/mst.h +++ b/drivers/net/ethernet/mellanox/mstflint_access/mst.h @@ -72,18 +72,18 @@ struct mst_params { #define MST_READ4 _IOR(MST_BYTE_ACCESS_MAGIC, 1, struct mst_read4_st) struct mst_read4_st { - unsigned int address_space; - unsigned int offset; - unsigned int data; /*OUT*/ + unsigned int address_space; + unsigned int offset; + unsigned int data; /*OUT*/ }; #define MST_WRITE4 _IOW(MST_BYTE_ACCESS_MAGIC, 2, struct mst_write4_st) struct mst_write4_st { - unsigned int address_space; - unsigned int offset; - unsigned int data; + unsigned int address_space; + unsigned int offset; + unsigned int data; }; @@ -113,20 +113,20 @@ struct mst_write_block_st { }; -#define PCICONF_READ4_BUFFER _IOR (MST_BLOCK_ACCESS_MAGIC, 3, struct mst_read4_st) +#define PCICONF_READ4_BUFFER _IOR(MST_BLOCK_ACCESS_MAGIC, 3, struct mst_read4_st) struct mst_read4_buffer_st { - unsigned int address_space; - unsigned int offset; - int size; - unsigned int data[PCICONF_MAX_BUFFER_SIZE/4]; /*OUT*/ + unsigned int address_space; + unsigned int offset; + int size; + unsigned int data[PCICONF_MAX_BUFFER_SIZE/4]; /*OUT*/ }; -#define PCICONF_WRITE4_BUFFER _IOW (MST_BLOCK_ACCESS_MAGIC, 4, struct mst_write4_buffer_st) +#define PCICONF_WRITE4_BUFFER _IOW(MST_BLOCK_ACCESS_MAGIC, 4, struct mst_write4_buffer_st) struct mst_write4_buffer_st { - unsigned int address_space; - unsigned int offset; - int size; - unsigned int data[PCICONF_MAX_BUFFER_SIZE/4]; /*IN*/ + unsigned int address_space; + unsigned int offset; + int size; + unsigned int data[PCICONF_MAX_BUFFER_SIZE/4]; /*IN*/ }; /****************************************************/ /* diff --git a/drivers/net/ethernet/mellanox/mstflint_access/mst_kernel.h b/drivers/net/ethernet/mellanox/mstflint_access/mst_kernel.h index d7188e9655690..fb52abc33cf4e 100644 --- a/drivers/net/ethernet/mellanox/mstflint_access/mst_kernel.h +++ b/drivers/net/ethernet/mellanox/mstflint_access/mst_kernel.h @@ -113,10 +113,10 @@ struct mst_dev_data { /****************************************************/ int pci_read4_vpd(struct mst_dev_data *dev, unsigned int timeout, - unsigned offset, u32 *buf); + unsigned int offset, u32 *buf); int pci_write4_vpd(struct mst_dev_data *dev, unsigned int timeout, - unsigned offset, u32 buf); + unsigned int offset, u32 buf); #endif /* _MST_KERNEL_H_ */ diff --git a/drivers/net/ethernet/mellanox/mstflint_access/mst_main.c b/drivers/net/ethernet/mellanox/mstflint_access/mst_main.c index 047cc98fda483..bc4079fc50756 100644 --- a/drivers/net/ethernet/mellanox/mstflint_access/mst_main.c +++ b/drivers/net/ethernet/mellanox/mstflint_access/mst_main.c @@ -33,7 +33,7 @@ #include #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) #include #else #include @@ -59,7 +59,7 @@ static const char mst_driver_string[] = "Mellanox Technologies Software Tools Dr LIST_HEAD(mst_devices); static struct pci_device_id mst_livefish_pci_table[] = { - { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 0x01f6) }, /* MT27500 [ConnectX-3 Flash Recovery] */ + { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 0x01f6) }, /* MT27500 [ConnectX-3 Flash Recovery] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 0x01f8) }, /* MT27520 [ConnectX-3 Pro Flash Recovery] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 0x01ff) }, /* MT27520 [ConnectX-IB Flash Recovery] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 0x0209) }, /* MT27520 [ConnectX-4 Flash Recovery] */ @@ -70,14 +70,14 @@ static struct pci_device_id mst_livefish_pci_table[] = { }; static struct pci_device_id mst_bar_pci_table[] = { - { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4099) }, /* MT27600 [ConnectX-3] */ - { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4103) }, /* MT27600 [ConnectX-3Pro] */ + { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4099) }, /* MT27600 [ConnectX-3] */ + { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4103) }, /* MT27600 [ConnectX-3Pro] */ { 0, } }; static struct pci_device_id supported_pci_devices[] = { - { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4099) }, /* MT27600 [ConnectX-3] */ - { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4103) }, /* MT27600 [ConnectX-3Pro] */ + { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4099) }, /* MT27600 [ConnectX-3] */ + { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4103) }, /* MT27600 [ConnectX-3Pro] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4113) }, /* MT27600 [ConnectX-IB] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4115) }, /* MT27600 [ConnectX-4] */ { PCI_DEVICE(MST_MELLANOX_PCI_VENDOR, 4117) }, /* MT27600 [ConnectX-4Lx] */ @@ -93,13 +93,13 @@ static struct pci_device_id supported_pci_devices[] = { // BIT Slicing macros #define ONES32(size) ((size)?(0xffffffff>>(32-(size))):0) -#define MASK32(offset,size) (ONES32(size)<<(offset)) +#define MASK32(offset, size) (ONES32(size)<<(offset)) -#define EXTRACT_C(source,offset,size) ((((unsigned)(source))>>(offset)) & ONES32(size)) -#define EXTRACT(src,start,len) (((len)==32)?(src):EXTRACT_C(src,start,len)) +#define EXTRACT_C(source, offset, size) ((((unsigned int)(source))>>(offset)) & ONES32(size)) +#define EXTRACT(src, start, len) (((len) == 32)?(src):EXTRACT_C(src, start, len)) -#define MERGE_C(rsrc1,rsrc2,start,len) ((((rsrc2)<<(start)) & (MASK32((start),(len)))) | ((rsrc1) & (~MASK32((start),(len))))) -#define MERGE(rsrc1,rsrc2,start,len) (((len)==32)?(rsrc2):MERGE_C(rsrc1,rsrc2,start,len)) +#define MERGE_C(rsrc1, rsrc2, start, len) ((((rsrc2)<<(start)) & (MASK32((start), (len)))) | ((rsrc1) & (~MASK32((start), (len))))) +#define MERGE(rsrc1, rsrc2, start, len) (((len) == 32)?(rsrc2):MERGE_C(rsrc1, rsrc2, start, len)) /* Allow minor numbers 0-255 */ @@ -163,34 +163,40 @@ static int _vendor_specific_sem(struct mst_dev_data *dev, int state) u32 counter = 0; int retries = 0; int ret; + if (!state) {// unlock - ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, 0); - if (ret) return ret; + ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, 0); + if (ret) + return ret; } else { // lock - do { - if (retries > SEM_MAX_RETRIES) { - return -1; - } - // read semaphore untill 0x0 - ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, &lock_val); - if (ret) return ret; - - if (lock_val) { //semaphore is taken - retries++; - msleep(1); // wait for current op to end - continue; - } - //read ticket - ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_COUNTER_OFFSET, &counter); - if (ret) return ret; - //write ticket to semaphore dword - ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, counter); - if (ret) return ret; - // read back semaphore make sure ticket == semaphore else repeat - ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, &lock_val); - if (ret) return ret; - retries++; - } while (counter != lock_val); + do { + if (retries > SEM_MAX_RETRIES) { + return -1; + } + // read semaphore untill 0x0 + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, &lock_val); + if (ret) + return ret; + + if (lock_val) { //semaphore is taken + retries++; + msleep(1); // wait for current op to end + continue; + } + //read ticket + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_COUNTER_OFFSET, &counter); + if (ret) + return ret; + //write ticket to semaphore dword + ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, counter); + if (ret) + return ret; + // read back semaphore make sure ticket == semaphore else repeat + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_SEMAPHORE_OFFSET, &lock_val); + if (ret) + return ret; + retries++; + } while (counter != lock_val); } return 0; } @@ -200,91 +206,101 @@ static int _wait_on_flag(struct mst_dev_data *dev, u8 expected_val) int retries = 0; int ret; u32 flag; + do { - if (retries > IFC_MAX_RETRIES) { - return -1; - } - - ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, &flag); - if (ret) return ret; - - flag = EXTRACT(flag, PCI_FLAG_BIT_OFFS, 1); - retries++; - if ((retries & 0xf) == 0) {// dont sleep always - //usleep_range(1,5); - } + if (retries > IFC_MAX_RETRIES) { + return -1; + } + + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, &flag); + if (ret) + return ret; + + flag = EXTRACT(flag, PCI_FLAG_BIT_OFFS, 1); + retries++; + if ((retries & 0xf) == 0) {// dont sleep always + //usleep_range(1,5); + } } while (flag != expected_val); return 0; } -static int _set_addr_space( struct mst_dev_data *dev, u16 space) +static int _set_addr_space(struct mst_dev_data *dev, u16 space) { // read modify write u32 val; int ret; + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_CTRL_OFFSET, &val); - if (ret) return ret; + if (ret) + return ret; val = MERGE(val, space, PCI_SPACE_BIT_OFFS, PCI_SPACE_BIT_LEN); ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_CTRL_OFFSET, val); - if (ret) return ret; + if (ret) + return ret; // read status and make sure space is supported ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_CTRL_OFFSET, &val); - if (ret) return ret; + if (ret) + return ret; if (EXTRACT(val, PCI_STATUS_BIT_OFFS, PCI_STATUS_BIT_LEN) == 0) { // mst_err("CRSPACE %d is not supported !\n", space); - return -1; + return -1; } // mst_err("CRSPACE %d is supported !\n", space); return 0; } -static int _pciconf_rw(struct mst_dev_data *dev, unsigned int offset, u32* data, int rw) +static int _pciconf_rw(struct mst_dev_data *dev, unsigned int offset, u32 *data, int rw) { int ret = 0; u32 address = offset; //last 2 bits must be zero as we only allow 30 bits addresses if (EXTRACT(address, 30, 2)) { - return -1; + return -1; } - address = MERGE(address,(rw ? 1 : 0), PCI_FLAG_BIT_OFFS, 1); + address = MERGE(address, (rw ? 1 : 0), PCI_FLAG_BIT_OFFS, 1); if (rw == WRITE_OP) { - // write data - ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_DATA_OFFSET, *data); - if (ret) return ret; - // write address - ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, address); - if (ret) return ret; - // wait on flag - ret = _wait_on_flag(dev, 0); + // write data + ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_DATA_OFFSET, *data); + if (ret) + return ret; + // write address + ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, address); + if (ret) + return ret; + // wait on flag + ret = _wait_on_flag(dev, 0); } else { - // write address - ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, address); - if (ret) return ret; - // wait on flag - ret = _wait_on_flag(dev, 1); - // read data - ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_DATA_OFFSET, data); - if (ret) return ret; + // write address + ret = pci_write_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_ADDR_OFFSET, address); + if (ret) + return ret; + // wait on flag + ret = _wait_on_flag(dev, 1); + // read data + ret = pci_read_config_dword(dev->pci_dev, dev->vendor_specific_cap + PCI_DATA_OFFSET, data); + if (ret) + return ret; } return ret; } -static int _send_pci_cmd_int( struct mst_dev_data *dev, int space, unsigned int offset, u32* data, int rw) +static int _send_pci_cmd_int(struct mst_dev_data *dev, int space, unsigned int offset, u32 *data, int rw) { int ret = 0; // take semaphore ret = _vendor_specific_sem(dev, 1); if (ret) { - return ret; + return ret; } // set address space ret = _set_addr_space(dev, space); if (ret) { - goto cleanup; + goto cleanup; } // read/write the data ret = _pciconf_rw(dev, offset, data, rw); @@ -294,55 +310,56 @@ cleanup: return ret; } -static int _block_op( struct mst_dev_data *dev, int space, unsigned int offset, int size, u32* data, int rw) +static int _block_op(struct mst_dev_data *dev, int space, unsigned int offset, int size, u32 *data, int rw) { int i; int ret = 0; int wrote_or_read = size; + if (size % 4) { - return -1; + return -1; } // lock semaphore and set address space ret = _vendor_specific_sem(dev, 1); if (ret) { - return -1; + return -1; } // set address space ret = _set_addr_space(dev, space); if (ret) { - wrote_or_read = -1; - goto cleanup; + wrote_or_read = -1; + goto cleanup; } for (i = 0; i < size ; i += 4) { - if (_pciconf_rw(dev, offset + i, &(data[(i >> 2)]), rw)) { - wrote_or_read = i; - goto cleanup; - } + if (_pciconf_rw(dev, offset + i, &(data[(i >> 2)]), rw)) { + wrote_or_read = i; + goto cleanup; + } } cleanup: _vendor_specific_sem(dev, 0); return wrote_or_read; } -static int write4_vsec( struct mst_dev_data *dev, int addresss_domain, unsigned int offset, unsigned int data) +static int write4_vsec(struct mst_dev_data *dev, int addresss_domain, unsigned int offset, unsigned int data) { int ret; ret = _send_pci_cmd_int(dev, addresss_domain, offset, &data, WRITE_OP); if (ret) { - return -1; + return -1; } return 0; } -static int read4_vsec( struct mst_dev_data *dev, int address_space, unsigned int offset, unsigned int* data) +static int read4_vsec(struct mst_dev_data *dev, int address_space, unsigned int offset, unsigned int *data) { int ret; //mst_info("Read from VSEC: offset: %#x\n", offset); ret = _send_pci_cmd_int(dev, address_space, offset, data, READ_OP); if (ret) { - return -1; + return -1; } return 0; } @@ -355,23 +372,23 @@ int pciconf_read4_legacy(struct mst_dev_data *dev, unsigned int offset, unsigned unsigned int new_offset = offset; //mst_info("pciconf_read4_legacy: offset: %#x\n", offset); if (dev->type != PCICONF) { - return -1; + return -1; } if (dev->wo_addr) { - new_offset |= 0x1; + new_offset |= 0x1; } /* write the wanted address to addr register */ res = pci_write_config_dword(dev->pci_dev, dev->addr_reg, new_offset); if (res) { - mst_err("pci_write_config_dword failed\n"); - return res; + mst_err("pci_write_config_dword failed\n"); + return res; } /* read the result from data register */ res = pci_read_config_dword(dev->pci_dev, dev->data_reg, data); if (res) { - mst_err("pci_read_config_dword failed\n"); - return res; + mst_err("pci_read_config_dword failed\n"); + return res; } return 0; } @@ -379,55 +396,56 @@ int pciconf_read4_legacy(struct mst_dev_data *dev, unsigned int offset, unsigned int pciconf_write4_legacy(struct mst_dev_data *dev, unsigned int offset, unsigned int data) { int res = 0; + if (dev->type != PCICONF) { - return -1; + return -1; } if (dev->wo_addr) { - /* - * Write operation with new WO GW - * 1. Write data - * 2. Write address - */ - - /* write the data to data register */ - res = pci_write_config_dword(dev->pci_dev, dev->data_reg, data); - if (res) { - mst_err("pci_write_config_dword failed\n"); - return res; - } - /* write the destination address to addr register */ - res = pci_write_config_dword(dev->pci_dev, dev->addr_reg, offset); - if (res) { - mst_err("pci_write_config_dword failed\n"); - return res; - } + /* + * Write operation with new WO GW + * 1. Write data + * 2. Write address + */ + + /* write the data to data register */ + res = pci_write_config_dword(dev->pci_dev, dev->data_reg, data); + if (res) { + mst_err("pci_write_config_dword failed\n"); + return res; + } + /* write the destination address to addr register */ + res = pci_write_config_dword(dev->pci_dev, dev->addr_reg, offset); + if (res) { + mst_err("pci_write_config_dword failed\n"); + return res; + } } else { - /* write the destination address to addr register */ - res = pci_write_config_dword(dev->pci_dev, dev->addr_reg, offset); - if (res) { - mst_err("pci_write_conflig_dword failed\n"); - return res; - } - - /* write the data to data register */ - res = pci_write_config_dword(dev->pci_dev, dev->data_reg, data); - if (res) { - mst_err("pci_write_config_dword failed\n"); - return res; - } + /* write the destination address to addr register */ + res = pci_write_config_dword(dev->pci_dev, dev->addr_reg, offset); + if (res) { + mst_err("pci_write_conflig_dword failed\n"); + return res; + } + + /* write the data to data register */ + res = pci_write_config_dword(dev->pci_dev, dev->data_reg, data); + if (res) { + mst_err("pci_write_config_dword failed\n"); + return res; + } } return 0; } -static int write4_block_vsec( struct mst_dev_data *dev, int address_space, unsigned int offset, int size, u32* data) +static int write4_block_vsec(struct mst_dev_data *dev, int address_space, unsigned int offset, int size, u32 *data) { // mst_info("HERE %#x %#x %#x\n", address_space, offset, *data); return _block_op(dev, address_space, offset, size, data, WRITE_OP); } -static int read4_block_vsec( struct mst_dev_data *dev, int address_space, unsigned int offset, int size, u32* data) +static int read4_block_vsec(struct mst_dev_data *dev, int address_space, unsigned int offset, int size, u32 *data) { // mst_info("HERE %#x %#x %#x\n", address_space, offset, *data); return _block_op(dev, address_space, offset, size, data, READ_OP); @@ -438,25 +456,25 @@ static int get_space_support_status(struct mst_dev_data *dev) int ret; // printk("[MST] Checking if the Vendor CAP %d supports the SPACES in devices\n", vend_cap); if (!dev->vendor_specific_cap) { - return 0; + return 0; } - if (dev->spaces_support_status != SS_UNINITIALIZED ) { - return 0; + if (dev->spaces_support_status != SS_UNINITIALIZED) { + return 0; } // take semaphore ret = _vendor_specific_sem(dev, 1); if (ret) { - mst_err("Failed to lock VSEC semaphore\n"); - return 1; + mst_err("Failed to lock VSEC semaphore\n"); + return 1; } - if( _set_addr_space(dev, AS_CR_SPACE) || + if (_set_addr_space(dev, AS_CR_SPACE) || _set_addr_space(dev, AS_ICMD) || - _set_addr_space(dev, AS_SEMAPHORE) ) { - mst_err("At least one SPACE is not supported\n"); - dev->spaces_support_status = SS_NOT_ALL_SPACES_SUPPORTED; + _set_addr_space(dev, AS_SEMAPHORE)) { + mst_err("At least one SPACE is not supported\n"); + dev->spaces_support_status = SS_NOT_ALL_SPACES_SUPPORTED; } else { - dev->spaces_support_status = SS_ALL_SPACES_SUPPORTED; + dev->spaces_support_status = SS_ALL_SPACES_SUPPORTED; } // clear semaphore _vendor_specific_sem(dev, 0); @@ -468,20 +486,21 @@ static int get_space_support_status(struct mst_dev_data *dev) #define WO_REG_ADDR_DATA 0xbadacce5 #define DEVID_OFFSET 0xf0014 -int is_wo_gw(struct pci_dev* pcidev, unsigned addr_reg) +int is_wo_gw(struct pci_dev *pcidev, unsigned int addr_reg) { int ret; unsigned int data = 0; + ret = pci_write_config_dword(pcidev, addr_reg, DEVID_OFFSET); if (ret) { - return 0; + return 0; } ret = pci_read_config_dword(pcidev, addr_reg, &data); if (ret) { - return 0; + return 0; } - if ( data == WO_REG_ADDR_DATA ) { - return 1; + if (data == WO_REG_ADDR_DATA) { + return 1; } return 0; } @@ -493,15 +512,15 @@ static int mst_open(struct inode *inode, struct file *file) struct mst_file_data *md = NULL; md = kmalloc(sizeof(struct mst_connectx_wa), GFP_KERNEL); - if (!md) { - return -ERESTARTSYS; - } + if (!md) { + return -ERESTARTSYS; + } memset(md, 0, sizeof(struct mst_connectx_wa)); file->private_data = md; - return 0; + return 0; } @@ -512,7 +531,7 @@ static int mst_release(struct inode *inode, struct file *file) struct mst_dev_data *dev = NULL; struct mst_dev_data *cur = NULL; unsigned int slot_mask; - struct mst_connectx_wa *md = file->private_data; + struct mst_connectx_wa *md = file->private_data; /* * make sure the device is available since it @@ -539,7 +558,7 @@ static int mst_release(struct inode *inode, struct file *file) /* * mst_info("CONNECTX_WA: Released slot %u. Current slots: %02x\n", - * md->connectx_wa_slot_p1 - 1, dev->connectx_wa_slots); + * md->connectx_wa_slot_p1 - 1, dev->connectx_wa_slots); */ md->connectx_wa_slot_p1 = 0; mutex_unlock(&dev->lock); @@ -680,24 +699,24 @@ static int mst_ioctl(struct inode *inode, struct file *file, goto fin; } // best effort : try to get space spport status if we fail assume we got vsec support. - get_space_support_status(dev); - paramst.domain = pci_domain_nr(dev->pci_dev->bus); - paramst.bus = dev->pci_dev->bus->number; - paramst.slot = PCI_SLOT(dev->pci_dev->devfn); + get_space_support_status(dev); + paramst.domain = pci_domain_nr(dev->pci_dev->bus); + paramst.bus = dev->pci_dev->bus->number; + paramst.slot = PCI_SLOT(dev->pci_dev->devfn); paramst.func = PCI_FUNC(dev->pci_dev->devfn); - paramst.bar = dev->bar; - paramst.device = dev->pci_dev->device; + paramst.bar = dev->bar; + paramst.device = dev->pci_dev->device; paramst.vendor = dev->pci_dev->vendor; - paramst.subsystem_device = dev->pci_dev->subsystem_device; + paramst.subsystem_device = dev->pci_dev->subsystem_device; paramst.subsystem_vendor = dev->pci_dev->subsystem_vendor; - if (dev->vendor_specific_cap && - (dev->spaces_support_status == SS_ALL_SPACES_SUPPORTED || - dev->spaces_support_status == SS_UNINITIALIZED) ) { - // assume supported if SS_UNINITIALIZED (since semaphore is locked) - paramst.vendor_specific_cap = dev->vendor_specific_cap; - } else { - paramst.vendor_specific_cap = 0; - } + if (dev->vendor_specific_cap && + (dev->spaces_support_status == SS_ALL_SPACES_SUPPORTED || + dev->spaces_support_status == SS_UNINITIALIZED)) { + // assume supported if SS_UNINITIALIZED (since semaphore is locked) + paramst.vendor_specific_cap = dev->vendor_specific_cap; + } else { + paramst.vendor_specific_cap = 0; + } if (copy_to_user(user_buf, ¶mst, sizeof(struct mst_params))) { res = -EFAULT; goto fin; @@ -723,19 +742,19 @@ static int mst_ioctl(struct inode *inode, struct file *file, switch (dev->type) { case PCICONF: - if (get_space_support_status(dev)) { - res = -EBUSY; - goto fin; - } - - if ( VSEC_FULLY_SUPPORTED(dev) ) { - res = read4_vsec(dev, readst.address_space, readst.offset, &out); - } else { - res = pciconf_read4_legacy(dev, readst.offset, &out); - } - if (res) { - goto fin; - } + if (get_space_support_status(dev)) { + res = -EBUSY; + goto fin; + } + + if (VSEC_FULLY_SUPPORTED(dev)) { + res = read4_vsec(dev, readst.address_space, readst.offset, &out); + } else { + res = pciconf_read4_legacy(dev, readst.offset, &out); + } + if (res) { + goto fin; + } break; case PCIMEM: @@ -749,8 +768,8 @@ static int mst_ioctl(struct inode *inode, struct file *file, out = ioread32(dev->hw_addr + readst.offset); /* endianness conversion - we noticed that we need to swap always */ - be32_to_cpus(&out); - out = cpu_to_le32(out); + be32_to_cpus(&out); + out = cpu_to_le32(out); break; } @@ -779,15 +798,15 @@ static int mst_ioctl(struct inode *inode, struct file *file, switch (dev->type) { case PCICONF: - if (get_space_support_status(dev)) { - res = -EBUSY; - goto fin; - } - if ( VSEC_FULLY_SUPPORTED(dev) ) { - res = write4_vsec(dev, writest.address_space, writest.offset, writest.data); - } else { - res = pciconf_write4_legacy(dev, writest.offset, writest.data); - } + if (get_space_support_status(dev)) { + res = -EBUSY; + goto fin; + } + if (VSEC_FULLY_SUPPORTED(dev)) { + res = write4_vsec(dev, writest.address_space, writest.offset, writest.data); + } else { + res = pciconf_write4_legacy(dev, writest.offset, writest.data); + } break; case PCIMEM: @@ -799,7 +818,7 @@ static int mst_ioctl(struct inode *inode, struct file *file, /* endianness conversion - we noticed that we need to swap always */ cpu_to_be32s(&(writest.data)); - writest.data = cpu_to_le32(writest.data); + writest.data = cpu_to_le32(writest.data); /* write to hardware */ iowrite32(writest.data, dev->hw_addr + writest.offset); @@ -912,86 +931,87 @@ static int mst_ioctl(struct inode *inode, struct file *file, break; } - case PCICONF_READ4_BUFFER: + case PCICONF_READ4_BUFFER: { - struct mst_read4_buffer_st read4_buf; - struct mst_read4_buffer_st* rb_udata = (struct mst_read4_buffer_st *)user_buf; - - if (!dev->initialized) { - mst_err("device is not initialized\n"); - res = -ENODEV; - goto fin; - } - - if (dev->type != PCICONF) { - mst_err("wrong type for device\n"); - res = -EPERM; - goto fin; - } - - if (get_space_support_status(dev)) { - res = -EBUSY; - goto fin; - } - - if (dev->spaces_support_status != SS_ALL_SPACES_SUPPORTED) { - res = -ENOSYS; - goto fin; - } - - - if (copy_from_user(&read4_buf, user_buf, sizeof(read4_buf))) { - res = -EFAULT; - goto fin; - } - - res = read4_block_vsec(dev, read4_buf.address_space, read4_buf.offset, read4_buf.size, read4_buf.data); - if (res != read4_buf.size) { - goto fin; - } - - res = copy_to_user(rb_udata, &read4_buf, sizeof(read4_buf)) ? -EFAULT : read4_buf.size; - goto fin; + struct mst_read4_buffer_st read4_buf; + struct mst_read4_buffer_st *rb_udata = (struct mst_read4_buffer_st *)user_buf; + + if (!dev->initialized) { + mst_err("device is not initialized\n"); + res = -ENODEV; + goto fin; + } + + if (dev->type != PCICONF) { + mst_err("wrong type for device\n"); + res = -EPERM; + goto fin; + } + + if (get_space_support_status(dev)) { + res = -EBUSY; + goto fin; + } + + if (dev->spaces_support_status != SS_ALL_SPACES_SUPPORTED) { + res = -ENOSYS; + goto fin; + } + + + if (copy_from_user(&read4_buf, user_buf, sizeof(read4_buf))) { + res = -EFAULT; + goto fin; + } + + res = read4_block_vsec(dev, read4_buf.address_space, read4_buf.offset, read4_buf.size, read4_buf.data); + if (res != read4_buf.size) { + goto fin; + } + + res = copy_to_user(rb_udata, &read4_buf, sizeof(read4_buf)) ? -EFAULT : read4_buf.size; + goto fin; } - case PCICONF_WRITE4_BUFFER: + case PCICONF_WRITE4_BUFFER: { - struct mst_write4_buffer_st write4_buf; - struct mst_write4_buffer_st* wb_udata = (struct mst_write4_buffer_st *)user_buf; + struct mst_write4_buffer_st write4_buf; + struct mst_write4_buffer_st *wb_udata = (struct mst_write4_buffer_st *)user_buf; - if (!dev->initialized) { - mst_err("device is not initialized\n"); - res = -ENODEV; - goto fin; - } + if (!dev->initialized) { + mst_err("device is not initialized\n"); + res = -ENODEV; + goto fin; + } - if (dev->type != PCICONF) { - mst_err("wrong type for device\n"); - res = -EPERM; - goto fin; - } + if (dev->type != PCICONF) { + mst_err("wrong type for device\n"); + res = -EPERM; + goto fin; + } - if (get_space_support_status(dev)) { - res = -EBUSY; - goto fin; - } + if (get_space_support_status(dev)) { + res = -EBUSY; + goto fin; + } - if (dev->spaces_support_status != SS_ALL_SPACES_SUPPORTED) { - res = -ENOSYS; - goto fin; - } + if (dev->spaces_support_status != SS_ALL_SPACES_SUPPORTED) { + res = -ENOSYS; + goto fin; + } - if (copy_from_user(&write4_buf, user_buf, sizeof(write4_buf))) { - res = -EFAULT; - goto fin; - } + if (copy_from_user(&write4_buf, user_buf, sizeof(write4_buf))) { + res = -EFAULT; + goto fin; + } - res = write4_block_vsec(dev, write4_buf.address_space, write4_buf.offset, write4_buf.size, write4_buf.data); - if (res != write4_buf.size) goto fin; + res = write4_block_vsec(dev, write4_buf.address_space, write4_buf.offset, write4_buf.size, write4_buf.data); + if (res != write4_buf.size) + goto fin; - res = copy_to_user(wb_udata, &write4_buf, sizeof(write4_buf)) ? -EFAULT : write4_buf.size; - goto fin; + res = copy_to_user(wb_udata, &write4_buf, sizeof(write4_buf)) ? -EFAULT : write4_buf.size; + goto fin; } case PCICONF_INIT: { struct mst_pciconf_init_st initst; @@ -1020,7 +1040,7 @@ static int mst_ioctl(struct inode *inode, struct file *file, dev->wo_addr = is_wo_gw(dev->pci_dev, initst.addr_reg); dev->vendor_specific_cap = pci_find_capability(dev->pci_dev, MLNX_VENDOR_SPECIFIC_CAP_ID); //mst_info("VSEC SUPP: %#x\n", dev->vendor_specific_cap); - dev->spaces_support_status = SS_UNINITIALIZED; // init on first op + dev->spaces_support_status = SS_UNINITIALIZED; // init on first op dev->initialized = 1; @@ -1139,7 +1159,7 @@ static int mst_ioctl(struct inode *inode, struct file *file, /* * mst_info("CONNECTX_WA: Took slot %u. Current slots: %02x\n", - * md->connectx_wa_slot_p1 - 1, dev->connectx_wa_slots); + * md->connectx_wa_slot_p1 - 1, dev->connectx_wa_slots); */ if (copy_to_user(user_buf, md, sizeof(struct mst_connectx_wa))) { res = -EFAULT; @@ -1177,7 +1197,7 @@ static int mst_ioctl(struct inode *inode, struct file *file, /* retrieve to user - we noticed that we need to swap always */ dataout = &((struct mst_vpd_read4_st *)user_buf)->data; - out = le32_to_cpu(out); + out = le32_to_cpu(out); if (copy_to_user(dataout, &out, sizeof(u32))) { res = -EFAULT; goto fin; @@ -1204,7 +1224,7 @@ static int mst_ioctl(struct inode *inode, struct file *file, res = -EFAULT; goto fin; } - writest.data = le32_to_cpu(writest.data); + writest.data = le32_to_cpu(writest.data); res = pci_write4_vpd(dev, writest.timeout, writest.offset, writest.data); if (res) { goto fin; @@ -1228,9 +1248,9 @@ fin_err: } #if HAVE_COMPAT_IOCTL -static long compat_ioctl (struct file *f, unsigned int o, unsigned long d) +static long compat_ioctl(struct file *f, unsigned int o, unsigned long d) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) struct inode *n = f->f_dentry->d_inode; #else struct inode *n = f->f_path.dentry->d_inode; @@ -1240,9 +1260,9 @@ static long compat_ioctl (struct file *f, unsigned int o, unsigned long d) #endif #ifdef HAVE_UNLOCKED_IOCTL -static long unlocked_ioctl (struct file *f, unsigned int o, unsigned long d) +static long unlocked_ioctl(struct file *f, unsigned int o, unsigned long d) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) struct inode *n = f->f_dentry->d_inode; #else struct inode *n = f->f_path.dentry->d_inode; @@ -1275,7 +1295,7 @@ static const struct file_operations mst_fops = { .unlocked_ioctl = unlocked_ioctl, #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) .ioctl = mst_ioctl, #endif @@ -1292,7 +1312,7 @@ static struct mst_dev_data *mst_device_create(enum dev_type type, struct pci_dev *pdev) { struct mst_dev_data *dev = NULL; - char dbdf[20]; + char dbdf[20]; dev = kzalloc(sizeof(struct mst_dev_data), GFP_KERNEL); if (!dev) { @@ -1302,7 +1322,7 @@ static struct mst_dev_data *mst_device_create(enum dev_type type, return NULL; } - sprintf(dbdf, "%4.4x:%2.2x:%2.2x.%1.1x", pci_domain_nr(pdev->bus), pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + sprintf(dbdf, "%4.4x:%2.2x:%2.2x.%1.1x", pci_domain_nr(pdev->bus), pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); switch (type) { case PCICONF: dev->addr_reg = MST_CONF_ADDR_REG; @@ -1312,15 +1332,15 @@ static struct mst_dev_data *mst_device_create(enum dev_type type, snprintf(dev->name, MST_NAME_SIZE, "%s" MST_PCICONF_DEVICE_NAME, - dbdf); + dbdf); break; case PCIMEM: dev->addr_reg = 0; /* invalid */ dev->data_reg = 0; /* invalid */ - dev->bar = 0; - dev->hw_addr = ioremap(pci_resource_start(pdev, dev->bar), + dev->bar = 0; + dev->hw_addr = ioremap(pci_resource_start(pdev, dev->bar), MST_MEMORY_SIZE); if (dev->hw_addr <= 0) { mst_err("could not map device memory, BAR: %x\n", dev->bar); @@ -1345,19 +1365,20 @@ static struct mst_dev_data *mst_device_create(enum dev_type type, dev->vpd_cap_addr = pci_find_capability(pdev, PCI_CAP_ID_VPD); if (alloc_chrdev_region(&dev->my_dev, 0, 1, dev->name)) { - mst_err("failed to allocate chrdev_region\n"); + mst_err("failed to allocate chrdev_region\n"); } - if ( (dev->cl = class_create( THIS_MODULE, dev->name ) ) == NULL ) { - printk(KERN_ALERT "Class creation failed\n"); - unregister_chrdev_region(dev->my_dev, 1); - goto out; + dev->cl = class_create(THIS_MODULE, dev->name); + if (dev->cl == NULL) { + printk(KERN_ALERT "Class creation failed\n"); + unregister_chrdev_region(dev->my_dev, 1); + goto out; } - if( device_create(dev->cl, NULL, dev->my_dev, NULL, dev->name) == NULL) { - printk(KERN_ALERT "Device creation failed\n"); - class_destroy(dev->cl); - unregister_chrdev_region(dev->my_dev , 1); - goto out; + if (device_create(dev->cl, NULL, dev->my_dev, NULL, dev->name) == NULL) { + printk(KERN_ALERT "Device creation failed\n"); + class_destroy(dev->cl); + unregister_chrdev_region(dev->my_dev, 1); + goto out; } dev->major = MAJOR(dev->my_dev); @@ -1365,13 +1386,13 @@ static struct mst_dev_data *mst_device_create(enum dev_type type, cdev_add(&dev->mcdev, dev->my_dev, 1); //TODO check if cdev_add fails if (type == PCICONF) { - /* - * Initialize 5th Gen attributes - */ - dev->wo_addr = is_wo_gw(dev->pci_dev, MST_CONF_ADDR_REG); - dev->vendor_specific_cap = pci_find_capability(dev->pci_dev, MLNX_VENDOR_SPECIFIC_CAP_ID); - //mst_info("VSEC SUPP: %#x\n", dev->vendor_specific_cap); - dev->spaces_support_status = SS_UNINITIALIZED; // init on first op + /* + * Initialize 5th Gen attributes + */ + dev->wo_addr = is_wo_gw(dev->pci_dev, MST_CONF_ADDR_REG); + dev->vendor_specific_cap = pci_find_capability(dev->pci_dev, MLNX_VENDOR_SPECIFIC_CAP_ID); + //mst_info("VSEC SUPP: %#x\n", dev->vendor_specific_cap); + dev->spaces_support_status = SS_UNINITIALIZED; // init on first op } dev->initialized = 1; list_add_tail(&dev->list, &mst_devices); @@ -1389,10 +1410,10 @@ static void mst_device_destroy(struct mst_dev_data *dev) iounmap(dev->hw_addr); } - cdev_del(&dev->mcdev); - device_destroy(dev->cl, dev->my_dev); - class_destroy(dev->cl); - unregister_chrdev_region(dev->my_dev, 1); + cdev_del(&dev->mcdev); + device_destroy(dev->cl, dev->my_dev); + class_destroy(dev->cl); + unregister_chrdev_region(dev->my_dev, 1); list_del(&dev->list); kfree(dev); } @@ -1410,9 +1431,9 @@ static int __init mst_init(void) mst_info("%s - version %s\n", mst_driver_string, mst_driver_version); while ((pdev = pci_get_device(MST_MELLANOX_PCI_VENDOR, PCI_ANY_ID, pdev)) != NULL) { - if (!pci_match_id(supported_pci_devices, pdev) && !pci_match_id(mst_livefish_pci_table, pdev)) { - continue; - } + if (!pci_match_id(supported_pci_devices, pdev) && !pci_match_id(mst_livefish_pci_table, pdev)) { + continue; + } device_exists = 0; list_for_each_entry(cur, &mst_devices, list) { if (cur->pci_dev->bus->number == pdev->bus->number) { @@ -1430,8 +1451,7 @@ static int __init mst_init(void) } /* found new device */ - mst_info("found device - " - "domain=0x%x, bus=0x%x, slot=0x%x, func=0x%x, vendor=0x%x, device=0x%x\n", + mst_info("found device - domain=0x%x, bus=0x%x, slot=0x%x, func=0x%x, vendor=0x%x, device=0x%x\n", pci_domain_nr(pdev->bus), pdev->bus->number, PCI_SLOT(pdev->devfn), diff --git a/drivers/net/ethernet/mellanox/mstflint_access/mst_vpd.c b/drivers/net/ethernet/mellanox/mstflint_access/mst_vpd.c index 36ebae1906fdb..60efa11dc76fb 100644 --- a/drivers/net/ethernet/mellanox/mstflint_access/mst_vpd.c +++ b/drivers/net/ethernet/mellanox/mstflint_access/mst_vpd.c @@ -37,7 +37,7 @@ /****************************************************/ int pci_read4_vpd(struct mst_dev_data *dev, unsigned int timeout, - unsigned offset, u32 *buf) + unsigned int offset, u32 *buf) { struct pci_dev *pci_dev = dev->pci_dev; int vpd_cap = dev->vpd_cap_addr; @@ -99,7 +99,7 @@ int pci_read4_vpd(struct mst_dev_data *dev, unsigned int timeout, EXPORT_SYMBOL(pci_read4_vpd); int pci_write4_vpd(struct mst_dev_data *dev, unsigned int timeout, - unsigned offset, u32 buf) + unsigned int offset, u32 buf) { struct pci_dev *pci_dev = dev->pci_dev; int vpd_cap = dev->vpd_cap_addr;