mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
thunderbolt: Use generic tb_nvm_[read|write]_data() for Thunderbolt 2/3 devices
Now that we have generic functionality available in nvm.c make the DMA port code call it instead of duplicating the functionality. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
This commit is contained in:
parent
9b38303777
commit
34163dfad4
@ -299,15 +299,13 @@ static int dma_port_request(struct tb_dma_port *dma, u32 in,
|
|||||||
return status_to_errno(out);
|
return status_to_errno(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dma_port_flash_read_block(struct tb_dma_port *dma, u32 address,
|
static int dma_port_flash_read_block(void *data, unsigned int dwaddress,
|
||||||
void *buf, u32 size)
|
void *buf, size_t dwords)
|
||||||
{
|
{
|
||||||
|
struct tb_dma_port *dma = data;
|
||||||
struct tb_switch *sw = dma->sw;
|
struct tb_switch *sw = dma->sw;
|
||||||
u32 in, dwaddress, dwords;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
u32 in;
|
||||||
dwaddress = address / 4;
|
|
||||||
dwords = size / 4;
|
|
||||||
|
|
||||||
in = MAIL_IN_CMD_FLASH_READ << MAIL_IN_CMD_SHIFT;
|
in = MAIL_IN_CMD_FLASH_READ << MAIL_IN_CMD_SHIFT;
|
||||||
if (dwords < MAIL_DATA_DWORDS)
|
if (dwords < MAIL_DATA_DWORDS)
|
||||||
@ -323,14 +321,13 @@ static int dma_port_flash_read_block(struct tb_dma_port *dma, u32 address,
|
|||||||
dma->base + MAIL_DATA, dwords, DMA_PORT_TIMEOUT);
|
dma->base + MAIL_DATA, dwords, DMA_PORT_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dma_port_flash_write_block(struct tb_dma_port *dma, u32 address,
|
static int dma_port_flash_write_block(void *data, unsigned int dwaddress,
|
||||||
const void *buf, u32 size)
|
const void *buf, size_t dwords)
|
||||||
{
|
{
|
||||||
|
struct tb_dma_port *dma = data;
|
||||||
struct tb_switch *sw = dma->sw;
|
struct tb_switch *sw = dma->sw;
|
||||||
u32 in, dwaddress, dwords;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
u32 in;
|
||||||
dwords = size / 4;
|
|
||||||
|
|
||||||
/* Write the block to MAIL_DATA registers */
|
/* Write the block to MAIL_DATA registers */
|
||||||
ret = dma_port_write(sw->tb->ctl, buf, tb_route(sw), dma->port,
|
ret = dma_port_write(sw->tb->ctl, buf, tb_route(sw), dma->port,
|
||||||
@ -341,12 +338,8 @@ static int dma_port_flash_write_block(struct tb_dma_port *dma, u32 address,
|
|||||||
in = MAIL_IN_CMD_FLASH_WRITE << MAIL_IN_CMD_SHIFT;
|
in = MAIL_IN_CMD_FLASH_WRITE << MAIL_IN_CMD_SHIFT;
|
||||||
|
|
||||||
/* CSS header write is always done to the same magic address */
|
/* CSS header write is always done to the same magic address */
|
||||||
if (address >= DMA_PORT_CSS_ADDRESS) {
|
if (dwaddress >= DMA_PORT_CSS_ADDRESS)
|
||||||
dwaddress = DMA_PORT_CSS_ADDRESS;
|
|
||||||
in |= MAIL_IN_CSS;
|
in |= MAIL_IN_CSS;
|
||||||
} else {
|
|
||||||
dwaddress = address / 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
in |= ((dwords - 1) << MAIL_IN_DWORDS_SHIFT) & MAIL_IN_DWORDS_MASK;
|
in |= ((dwords - 1) << MAIL_IN_DWORDS_SHIFT) & MAIL_IN_DWORDS_MASK;
|
||||||
in |= (dwaddress << MAIL_IN_ADDRESS_SHIFT) & MAIL_IN_ADDRESS_MASK;
|
in |= (dwaddress << MAIL_IN_ADDRESS_SHIFT) & MAIL_IN_ADDRESS_MASK;
|
||||||
@ -365,36 +358,8 @@ static int dma_port_flash_write_block(struct tb_dma_port *dma, u32 address,
|
|||||||
int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
|
int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
|
||||||
void *buf, size_t size)
|
void *buf, size_t size)
|
||||||
{
|
{
|
||||||
unsigned int retries = DMA_PORT_RETRIES;
|
return tb_nvm_read_data(address, buf, size, DMA_PORT_RETRIES,
|
||||||
|
dma_port_flash_read_block, dma);
|
||||||
do {
|
|
||||||
unsigned int offset;
|
|
||||||
size_t nbytes;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
offset = address & 3;
|
|
||||||
nbytes = min_t(size_t, size + offset, MAIL_DATA_DWORDS * 4);
|
|
||||||
|
|
||||||
ret = dma_port_flash_read_block(dma, address, dma->buf,
|
|
||||||
ALIGN(nbytes, 4));
|
|
||||||
if (ret) {
|
|
||||||
if (ret == -ETIMEDOUT) {
|
|
||||||
if (retries--)
|
|
||||||
continue;
|
|
||||||
ret = -EIO;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbytes -= offset;
|
|
||||||
memcpy(buf, dma->buf + offset, nbytes);
|
|
||||||
|
|
||||||
size -= nbytes;
|
|
||||||
address += nbytes;
|
|
||||||
buf += nbytes;
|
|
||||||
} while (size > 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -411,40 +376,11 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
|
|||||||
int dma_port_flash_write(struct tb_dma_port *dma, unsigned int address,
|
int dma_port_flash_write(struct tb_dma_port *dma, unsigned int address,
|
||||||
const void *buf, size_t size)
|
const void *buf, size_t size)
|
||||||
{
|
{
|
||||||
unsigned int retries = DMA_PORT_RETRIES;
|
if (address >= DMA_PORT_CSS_ADDRESS && size > DMA_PORT_CSS_MAX_SIZE)
|
||||||
unsigned int offset;
|
return -E2BIG;
|
||||||
|
|
||||||
if (address >= DMA_PORT_CSS_ADDRESS) {
|
return tb_nvm_write_data(address, buf, size, DMA_PORT_RETRIES,
|
||||||
offset = 0;
|
dma_port_flash_write_block, dma);
|
||||||
if (size > DMA_PORT_CSS_MAX_SIZE)
|
|
||||||
return -E2BIG;
|
|
||||||
} else {
|
|
||||||
offset = address & 3;
|
|
||||||
address = address & ~3;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
u32 nbytes = min_t(u32, size, MAIL_DATA_DWORDS * 4);
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
memcpy(dma->buf + offset, buf, nbytes);
|
|
||||||
|
|
||||||
ret = dma_port_flash_write_block(dma, address, buf, nbytes);
|
|
||||||
if (ret) {
|
|
||||||
if (ret == -ETIMEDOUT) {
|
|
||||||
if (retries--)
|
|
||||||
continue;
|
|
||||||
ret = -EIO;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
size -= nbytes;
|
|
||||||
address += nbytes;
|
|
||||||
buf += nbytes;
|
|
||||||
} while (size > 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user