Commit 920767a9 authored by David S. Miller's avatar David S. Miller

Merge branch 'liquidio-improve-soft-command-response-handling'

Weilin Chang says:

====================
liquidio: improve soft command/response handling

Change soft command handling to fix the possible race condition when the
process handles a response of a soft command that was already freed by an
application which got timeout for this request.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0927f71d 64fecd3e
...@@ -49,44 +49,25 @@ static const struct net_device_ops lio_vf_rep_ndev_ops = { ...@@ -49,44 +49,25 @@ static const struct net_device_ops lio_vf_rep_ndev_ops = {
.ndo_change_mtu = lio_vf_rep_change_mtu, .ndo_change_mtu = lio_vf_rep_change_mtu,
}; };
static void
lio_vf_rep_send_sc_complete(struct octeon_device *oct,
u32 status, void *ptr)
{
struct octeon_soft_command *sc = (struct octeon_soft_command *)ptr;
struct lio_vf_rep_sc_ctx *ctx =
(struct lio_vf_rep_sc_ctx *)sc->ctxptr;
struct lio_vf_rep_resp *resp =
(struct lio_vf_rep_resp *)sc->virtrptr;
if (status != OCTEON_REQUEST_TIMEOUT && READ_ONCE(resp->status))
WRITE_ONCE(resp->status, 0);
complete(&ctx->complete);
}
static int static int
lio_vf_rep_send_soft_command(struct octeon_device *oct, lio_vf_rep_send_soft_command(struct octeon_device *oct,
void *req, int req_size, void *req, int req_size,
void *resp, int resp_size) void *resp, int resp_size)
{ {
int tot_resp_size = sizeof(struct lio_vf_rep_resp) + resp_size; int tot_resp_size = sizeof(struct lio_vf_rep_resp) + resp_size;
int ctx_size = sizeof(struct lio_vf_rep_sc_ctx);
struct octeon_soft_command *sc = NULL; struct octeon_soft_command *sc = NULL;
struct lio_vf_rep_resp *rep_resp; struct lio_vf_rep_resp *rep_resp;
struct lio_vf_rep_sc_ctx *ctx;
void *sc_req; void *sc_req;
int err; int err;
sc = (struct octeon_soft_command *) sc = (struct octeon_soft_command *)
octeon_alloc_soft_command(oct, req_size, octeon_alloc_soft_command(oct, req_size,
tot_resp_size, ctx_size); tot_resp_size, 0);
if (!sc) if (!sc)
return -ENOMEM; return -ENOMEM;
ctx = (struct lio_vf_rep_sc_ctx *)sc->ctxptr; init_completion(&sc->complete);
memset(ctx, 0, ctx_size); sc->sc_status = OCTEON_REQUEST_PENDING;
init_completion(&ctx->complete);
sc_req = (struct lio_vf_rep_req *)sc->virtdptr; sc_req = (struct lio_vf_rep_req *)sc->virtdptr;
memcpy(sc_req, req, req_size); memcpy(sc_req, req, req_size);
...@@ -98,23 +79,24 @@ lio_vf_rep_send_soft_command(struct octeon_device *oct, ...@@ -98,23 +79,24 @@ lio_vf_rep_send_soft_command(struct octeon_device *oct,
sc->iq_no = 0; sc->iq_no = 0;
octeon_prepare_soft_command(oct, sc, OPCODE_NIC, octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
OPCODE_NIC_VF_REP_CMD, 0, 0, 0); OPCODE_NIC_VF_REP_CMD, 0, 0, 0);
sc->callback = lio_vf_rep_send_sc_complete;
sc->callback_arg = sc;
sc->wait_time = LIO_VF_REP_REQ_TMO_MS;
err = octeon_send_soft_command(oct, sc); err = octeon_send_soft_command(oct, sc);
if (err == IQ_SEND_FAILED) if (err == IQ_SEND_FAILED)
goto free_buff; goto free_buff;
wait_for_completion_timeout(&ctx->complete, err = wait_for_sc_completion_timeout(oct, sc, 0);
msecs_to_jiffies if (err)
(2 * LIO_VF_REP_REQ_TMO_MS)); return err;
err = READ_ONCE(rep_resp->status) ? -EBUSY : 0; err = READ_ONCE(rep_resp->status) ? -EBUSY : 0;
if (err) if (err)
dev_err(&oct->pci_dev->dev, "VF rep send config failed\n"); dev_err(&oct->pci_dev->dev, "VF rep send config failed\n");
else if (resp)
if (resp)
memcpy(resp, (rep_resp + 1), resp_size); memcpy(resp, (rep_resp + 1), resp_size);
WRITE_ONCE(sc->caller_is_done, true);
return err;
free_buff: free_buff:
octeon_free_soft_command(oct, sc); octeon_free_soft_command(oct, sc);
...@@ -404,7 +386,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -404,7 +386,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
} }
sc = (struct octeon_soft_command *) sc = (struct octeon_soft_command *)
octeon_alloc_soft_command(oct, 0, 0, 0); octeon_alloc_soft_command(oct, 0, 16, 0);
if (!sc) { if (!sc) {
dev_err(&oct->pci_dev->dev, "VF rep: Soft command alloc failed\n"); dev_err(&oct->pci_dev->dev, "VF rep: Soft command alloc failed\n");
goto xmit_failed; goto xmit_failed;
...@@ -413,6 +395,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -413,6 +395,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
/* Multiple buffers are not used for vf_rep packets. */ /* Multiple buffers are not used for vf_rep packets. */
if (skb_shinfo(skb)->nr_frags != 0) { if (skb_shinfo(skb)->nr_frags != 0) {
dev_err(&oct->pci_dev->dev, "VF rep: nr_frags != 0. Dropping packet\n"); dev_err(&oct->pci_dev->dev, "VF rep: nr_frags != 0. Dropping packet\n");
octeon_free_soft_command(oct, sc);
goto xmit_failed; goto xmit_failed;
} }
...@@ -420,6 +403,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -420,6 +403,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
skb->data, skb->len, DMA_TO_DEVICE); skb->data, skb->len, DMA_TO_DEVICE);
if (dma_mapping_error(&oct->pci_dev->dev, sc->dmadptr)) { if (dma_mapping_error(&oct->pci_dev->dev, sc->dmadptr)) {
dev_err(&oct->pci_dev->dev, "VF rep: DMA mapping failed\n"); dev_err(&oct->pci_dev->dev, "VF rep: DMA mapping failed\n");
octeon_free_soft_command(oct, sc);
goto xmit_failed; goto xmit_failed;
} }
...@@ -440,6 +424,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -440,6 +424,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
if (status == IQ_SEND_FAILED) { if (status == IQ_SEND_FAILED) {
dma_unmap_single(&oct->pci_dev->dev, sc->dmadptr, dma_unmap_single(&oct->pci_dev->dev, sc->dmadptr,
sc->datasize, DMA_TO_DEVICE); sc->datasize, DMA_TO_DEVICE);
octeon_free_soft_command(oct, sc);
goto xmit_failed; goto xmit_failed;
} }
......
...@@ -438,9 +438,10 @@ struct octeon_config { ...@@ -438,9 +438,10 @@ struct octeon_config {
#define MAX_BAR1_IOREMAP_SIZE (16 * OCTEON_BAR1_ENTRY_SIZE) #define MAX_BAR1_IOREMAP_SIZE (16 * OCTEON_BAR1_ENTRY_SIZE)
/* Response lists - 1 ordered, 1 unordered-blocking, 1 unordered-nonblocking /* Response lists - 1 ordered, 1 unordered-blocking, 1 unordered-nonblocking
* 1 process done list, 1 zombie lists(timeouted sc list)
* NoResponse Lists are now maintained with each IQ. (Dec' 2007). * NoResponse Lists are now maintained with each IQ. (Dec' 2007).
*/ */
#define MAX_RESPONSE_LISTS 4 #define MAX_RESPONSE_LISTS 6
/* Opcode hash bits. The opcode is hashed on the lower 6-bits to lookup the /* Opcode hash bits. The opcode is hashed on the lower 6-bits to lookup the
* dispatch table. * dispatch table.
......
...@@ -292,13 +292,19 @@ struct octeon_soft_command { ...@@ -292,13 +292,19 @@ struct octeon_soft_command {
u32 ctxsize; u32 ctxsize;
/** Time out and callback */ /** Time out and callback */
size_t wait_time; size_t expiry_time;
size_t timeout;
u32 iq_no; u32 iq_no;
void (*callback)(struct octeon_device *, u32, void *); void (*callback)(struct octeon_device *, u32, void *);
void *callback_arg; void *callback_arg;
int caller_is_done;
u32 sc_status;
struct completion complete;
}; };
/* max timeout (in milli sec) for soft request */
#define LIO_SC_MAX_TMO_MS 60000
/** Maximum number of buffers to allocate into soft command buffer pool /** Maximum number of buffers to allocate into soft command buffer pool
*/ */
#define MAX_SOFT_COMMAND_BUFFERS 256 #define MAX_SOFT_COMMAND_BUFFERS 256
...@@ -319,6 +325,8 @@ struct octeon_sc_buffer_pool { ...@@ -319,6 +325,8 @@ struct octeon_sc_buffer_pool {
(((octeon_dev_ptr)->instr_queue[iq_no]->stats.field) += count) (((octeon_dev_ptr)->instr_queue[iq_no]->stats.field) += count)
int octeon_setup_sc_buffer_pool(struct octeon_device *oct); int octeon_setup_sc_buffer_pool(struct octeon_device *oct);
int octeon_free_sc_done_list(struct octeon_device *oct);
int octeon_free_sc_zombie_list(struct octeon_device *oct);
int octeon_free_sc_buffer_pool(struct octeon_device *oct); int octeon_free_sc_buffer_pool(struct octeon_device *oct);
struct octeon_soft_command * struct octeon_soft_command *
octeon_alloc_soft_command(struct octeon_device *oct, octeon_alloc_soft_command(struct octeon_device *oct,
......
...@@ -146,46 +146,70 @@ static inline int octeon_map_pci_barx(struct octeon_device *oct, ...@@ -146,46 +146,70 @@ static inline int octeon_map_pci_barx(struct octeon_device *oct,
return 1; return 1;
} }
/* input parameter:
* sc: pointer to a soft request
* timeout: milli sec which an application wants to wait for the
response of the request.
* 0: the request will wait until its response gets back
* from the firmware within LIO_SC_MAX_TMO_MS milli sec.
* It the response does not return within
* LIO_SC_MAX_TMO_MS milli sec, lio_process_ordered_list()
* will move the request to zombie response list.
*
* return value:
* 0: got the response from firmware for the sc request.
* errno -EINTR: user abort the command.
* errno -ETIME: user spefified timeout value has been expired.
* errno -EBUSY: the response of the request does not return in
* resonable time (LIO_SC_MAX_TMO_MS).
* the sc wll be move to zombie response list by
* lio_process_ordered_list()
*
* A request with non-zero return value, the sc->caller_is_done
* will be marked 1.
* When getting a request with zero return value, the requestor
* should mark sc->caller_is_done with 1 after examing the
* response of sc.
* lio_process_ordered_list() will free the soft command on behalf
* of the soft command requestor.
* This is to fix the possible race condition of both timeout process
* and lio_process_ordered_list()/callback function to free a
* sc strucutre.
*/
static inline int static inline int
sleep_cond(wait_queue_head_t *wait_queue, int *condition) wait_for_sc_completion_timeout(struct octeon_device *oct_dev,
struct octeon_soft_command *sc,
unsigned long timeout)
{ {
int errno = 0; int errno = 0;
wait_queue_entry_t we; long timeout_jiff;
init_waitqueue_entry(&we, current); if (timeout)
add_wait_queue(wait_queue, &we); timeout_jiff = msecs_to_jiffies(timeout);
while (!(READ_ONCE(*condition))) { else
set_current_state(TASK_INTERRUPTIBLE); timeout_jiff = MAX_SCHEDULE_TIMEOUT;
if (signal_pending(current)) {
timeout_jiff =
wait_for_completion_interruptible_timeout(&sc->complete,
timeout_jiff);
if (timeout_jiff == 0) {
dev_err(&oct_dev->pci_dev->dev, "%s: sc is timeout\n",
__func__);
WRITE_ONCE(sc->caller_is_done, true);
errno = -ETIME;
} else if (timeout_jiff == -ERESTARTSYS) {
dev_err(&oct_dev->pci_dev->dev, "%s: sc is interrupted\n",
__func__);
WRITE_ONCE(sc->caller_is_done, true);
errno = -EINTR; errno = -EINTR;
goto out; } else if (sc->sc_status == OCTEON_REQUEST_TIMEOUT) {
} dev_err(&oct_dev->pci_dev->dev, "%s: sc has fatal timeout\n",
schedule(); __func__);
WRITE_ONCE(sc->caller_is_done, true);
errno = -EBUSY;
} }
out:
set_current_state(TASK_RUNNING);
remove_wait_queue(wait_queue, &we);
return errno;
}
/* Gives up the CPU for a timeout period. return errno;
* Check that the condition is not true before we go to sleep for a
* timeout period.
*/
static inline void
sleep_timeout_cond(wait_queue_head_t *wait_queue,
int *condition,
int timeout)
{
wait_queue_entry_t we;
init_waitqueue_entry(&we, current);
add_wait_queue(wait_queue, &we);
set_current_state(TASK_INTERRUPTIBLE);
if (!(*condition))
schedule_timeout(timeout);
set_current_state(TASK_RUNNING);
remove_wait_queue(wait_queue, &we);
} }
#ifndef ROUNDUP4 #ifndef ROUNDUP4
......
...@@ -35,12 +35,6 @@ ...@@ -35,12 +35,6 @@
#define LIO_IFSTATE_RX_TIMESTAMP_ENABLED 0x08 #define LIO_IFSTATE_RX_TIMESTAMP_ENABLED 0x08
#define LIO_IFSTATE_RESETTING 0x10 #define LIO_IFSTATE_RESETTING 0x10
struct liquidio_if_cfg_context {
u32 octeon_id;
wait_queue_head_t wc;
int cond;
};
struct liquidio_if_cfg_resp { struct liquidio_if_cfg_resp {
u64 rh; u64 rh;
struct liquidio_if_cfg_info cfg_info; struct liquidio_if_cfg_info cfg_info;
...@@ -87,12 +81,6 @@ struct oct_nic_seapi_resp { ...@@ -87,12 +81,6 @@ struct oct_nic_seapi_resp {
u64 status; u64 status;
}; };
struct liquidio_nic_seapi_ctl_context {
int octeon_id;
u32 status;
struct completion complete;
};
/** LiquidIO per-interface network private data */ /** LiquidIO per-interface network private data */
struct lio { struct lio {
/** State of the interface. Rx/Tx happens only in the RUNNING state. */ /** State of the interface. Rx/Tx happens only in the RUNNING state. */
...@@ -234,10 +222,6 @@ int lio_wait_for_clean_oq(struct octeon_device *oct); ...@@ -234,10 +222,6 @@ int lio_wait_for_clean_oq(struct octeon_device *oct);
*/ */
void liquidio_set_ethtool_ops(struct net_device *netdev); void liquidio_set_ethtool_ops(struct net_device *netdev);
void lio_if_cfg_callback(struct octeon_device *oct,
u32 status __attribute__((unused)),
void *buf);
void lio_delete_glists(struct lio *lio); void lio_delete_glists(struct lio *lio);
int lio_setup_glists(struct octeon_device *oct, struct lio *lio, int num_qs); int lio_setup_glists(struct octeon_device *oct, struct lio *lio, int num_qs);
......
...@@ -75,8 +75,7 @@ octeon_alloc_soft_command_resp(struct octeon_device *oct, ...@@ -75,8 +75,7 @@ octeon_alloc_soft_command_resp(struct octeon_device *oct,
else else
sc->cmd.cmd2.rptr = sc->dmarptr; sc->cmd.cmd2.rptr = sc->dmarptr;
sc->wait_time = 1000; sc->expiry_time = jiffies + msecs_to_jiffies(LIO_SC_MAX_TMO_MS);
sc->timeout = jiffies + sc->wait_time;
return sc; return sc;
} }
...@@ -92,29 +91,6 @@ int octnet_send_nic_data_pkt(struct octeon_device *oct, ...@@ -92,29 +91,6 @@ int octnet_send_nic_data_pkt(struct octeon_device *oct,
ndata->reqtype); ndata->reqtype);
} }
static void octnet_link_ctrl_callback(struct octeon_device *oct,
u32 status,
void *sc_ptr)
{
struct octeon_soft_command *sc = (struct octeon_soft_command *)sc_ptr;
struct octnic_ctrl_pkt *nctrl;
nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;
/* Call the callback function if status is zero (meaning OK) or status
* contains a firmware status code bigger than zero (meaning the
* firmware is reporting an error).
* If no response was expected, status is OK if the command was posted
* successfully.
*/
if ((!status || status > FIRMWARE_STATUS_CODE(0)) && nctrl->cb_fn) {
nctrl->status = status;
nctrl->cb_fn(nctrl);
}
octeon_free_soft_command(oct, sc);
}
static inline struct octeon_soft_command static inline struct octeon_soft_command
*octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct, *octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct,
struct octnic_ctrl_pkt *nctrl) struct octnic_ctrl_pkt *nctrl)
...@@ -127,17 +103,14 @@ static inline struct octeon_soft_command ...@@ -127,17 +103,14 @@ static inline struct octeon_soft_command
uddsize = (u32)(nctrl->ncmd.s.more * 8); uddsize = (u32)(nctrl->ncmd.s.more * 8);
datasize = OCTNET_CMD_SIZE + uddsize; datasize = OCTNET_CMD_SIZE + uddsize;
rdatasize = (nctrl->wait_time) ? 16 : 0; rdatasize = 16;
sc = (struct octeon_soft_command *) sc = (struct octeon_soft_command *)
octeon_alloc_soft_command(oct, datasize, rdatasize, octeon_alloc_soft_command(oct, datasize, rdatasize, 0);
sizeof(struct octnic_ctrl_pkt));
if (!sc) if (!sc)
return NULL; return NULL;
memcpy(sc->ctxptr, nctrl, sizeof(struct octnic_ctrl_pkt));
data = (u8 *)sc->virtdptr; data = (u8 *)sc->virtdptr;
memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE); memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE);
...@@ -154,9 +127,8 @@ static inline struct octeon_soft_command ...@@ -154,9 +127,8 @@ static inline struct octeon_soft_command
octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD, octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD,
0, 0, 0); 0, 0, 0);
sc->callback = octnet_link_ctrl_callback; init_completion(&sc->complete);
sc->callback_arg = sc; sc->sc_status = OCTEON_REQUEST_PENDING;
sc->wait_time = nctrl->wait_time;
return sc; return sc;
} }
...@@ -199,5 +171,26 @@ octnet_send_nic_ctrl_pkt(struct octeon_device *oct, ...@@ -199,5 +171,26 @@ octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
} }
spin_unlock_bh(&oct->cmd_resp_wqlock); spin_unlock_bh(&oct->cmd_resp_wqlock);
switch (nctrl->ncmd.s.cmd) {
/* caller holds lock, can not sleep */
case OCTNET_CMD_CHANGE_DEVFLAGS:
case OCTNET_CMD_SET_MULTI_LIST:
case OCTNET_CMD_SET_UC_LIST:
WRITE_ONCE(sc->caller_is_done, true);
return retval;
}
retval = wait_for_sc_completion_timeout(oct, sc, 0);
if (retval)
return (retval);
nctrl->sc_status = sc->sc_status;
retval = nctrl->sc_status;
if (nctrl->cb_fn)
nctrl->cb_fn(nctrl);
WRITE_ONCE(sc->caller_is_done, true);
return retval; return retval;
} }
...@@ -52,20 +52,13 @@ struct octnic_ctrl_pkt { ...@@ -52,20 +52,13 @@ struct octnic_ctrl_pkt {
/** Input queue to use to send this command. */ /** Input queue to use to send this command. */
u64 iq_no; u64 iq_no;
/** Time to wait for Octeon software to respond to this control command.
* If wait_time is 0, OSI assumes no response is expected.
*/
size_t wait_time;
/** The network device that issued the control command. */ /** The network device that issued the control command. */
u64 netpndev; u64 netpndev;
/** Callback function called when the command has been fetched */ /** Callback function called when the command has been fetched */
octnic_ctrl_pkt_cb_fn_t cb_fn; octnic_ctrl_pkt_cb_fn_t cb_fn;
u32 status; u32 sc_status;
u16 *response_code;
struct completion *completion;
}; };
#define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd)) #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
......
...@@ -409,33 +409,22 @@ lio_process_iq_request_list(struct octeon_device *oct, ...@@ -409,33 +409,22 @@ lio_process_iq_request_list(struct octeon_device *oct,
else else
irh = (struct octeon_instr_irh *) irh = (struct octeon_instr_irh *)
&sc->cmd.cmd2.irh; &sc->cmd.cmd2.irh;
if (irh->rflag) {
/* We're expecting a response from Octeon. /* We're expecting a response from Octeon.
* It's up to lio_process_ordered_list() to * It's up to lio_process_ordered_list() to
* process sc. Add sc to the ordered soft * process sc. Add sc to the ordered soft
* command response list because we expect * command response list because we expect
* a response from Octeon. * a response from Octeon.
*/ */
spin_lock_irqsave spin_lock_irqsave(&oct->response_list
(&oct->response_list [OCTEON_ORDERED_SC_LIST].lock, flags);
[OCTEON_ORDERED_SC_LIST].lock,
flags);
atomic_inc(&oct->response_list atomic_inc(&oct->response_list
[OCTEON_ORDERED_SC_LIST]. [OCTEON_ORDERED_SC_LIST].pending_req_count);
pending_req_count);
list_add_tail(&sc->node, &oct->response_list list_add_tail(&sc->node, &oct->response_list
[OCTEON_ORDERED_SC_LIST].head); [OCTEON_ORDERED_SC_LIST].head);
spin_unlock_irqrestore spin_unlock_irqrestore(&oct->response_list
(&oct->response_list
[OCTEON_ORDERED_SC_LIST].lock, [OCTEON_ORDERED_SC_LIST].lock,
flags); flags);
} else {
if (sc->callback) {
/* This callback must not sleep */
sc->callback(oct, OCTEON_REQUEST_DONE,
sc->callback_arg);
}
}
break; break;
default: default:
dev_err(&oct->pci_dev->dev, dev_err(&oct->pci_dev->dev,
...@@ -755,8 +744,7 @@ int octeon_send_soft_command(struct octeon_device *oct, ...@@ -755,8 +744,7 @@ int octeon_send_soft_command(struct octeon_device *oct,
len = (u32)ih2->dlengsz; len = (u32)ih2->dlengsz;
} }
if (sc->wait_time) sc->expiry_time = jiffies + msecs_to_jiffies(LIO_SC_MAX_TMO_MS);
sc->timeout = jiffies + sc->wait_time;
return (octeon_send_command(oct, sc->iq_no, 1, &sc->cmd, sc, return (octeon_send_command(oct, sc->iq_no, 1, &sc->cmd, sc,
len, REQTYPE_SOFT_COMMAND)); len, REQTYPE_SOFT_COMMAND));
...@@ -791,11 +779,76 @@ int octeon_setup_sc_buffer_pool(struct octeon_device *oct) ...@@ -791,11 +779,76 @@ int octeon_setup_sc_buffer_pool(struct octeon_device *oct)
return 0; return 0;
} }
int octeon_free_sc_done_list(struct octeon_device *oct)
{
struct octeon_response_list *done_sc_list, *zombie_sc_list;
struct octeon_soft_command *sc;
struct list_head *tmp, *tmp2;
spinlock_t *sc_lists_lock; /* lock for response_list */
done_sc_list = &oct->response_list[OCTEON_DONE_SC_LIST];
zombie_sc_list = &oct->response_list[OCTEON_ZOMBIE_SC_LIST];
if (!atomic_read(&done_sc_list->pending_req_count))
return 0;
sc_lists_lock = &oct->response_list[OCTEON_ORDERED_SC_LIST].lock;
spin_lock_bh(sc_lists_lock);
list_for_each_safe(tmp, tmp2, &done_sc_list->head) {
sc = list_entry(tmp, struct octeon_soft_command, node);
if (READ_ONCE(sc->caller_is_done)) {
list_del(&sc->node);
atomic_dec(&done_sc_list->pending_req_count);
if (*sc->status_word == COMPLETION_WORD_INIT) {
/* timeout; move sc to zombie list */
list_add_tail(&sc->node, &zombie_sc_list->head);
atomic_inc(&zombie_sc_list->pending_req_count);
} else {
octeon_free_soft_command(oct, sc);
}
}
}
spin_unlock_bh(sc_lists_lock);
return 0;
}
int octeon_free_sc_zombie_list(struct octeon_device *oct)
{
struct octeon_response_list *zombie_sc_list;
struct octeon_soft_command *sc;
struct list_head *tmp, *tmp2;
spinlock_t *sc_lists_lock; /* lock for response_list */
zombie_sc_list = &oct->response_list[OCTEON_ZOMBIE_SC_LIST];
sc_lists_lock = &oct->response_list[OCTEON_ORDERED_SC_LIST].lock;
spin_lock_bh(sc_lists_lock);
list_for_each_safe(tmp, tmp2, &zombie_sc_list->head) {
list_del(tmp);
atomic_dec(&zombie_sc_list->pending_req_count);
sc = list_entry(tmp, struct octeon_soft_command, node);
octeon_free_soft_command(oct, sc);
}
spin_unlock_bh(sc_lists_lock);
return 0;
}
int octeon_free_sc_buffer_pool(struct octeon_device *oct) int octeon_free_sc_buffer_pool(struct octeon_device *oct)
{ {
struct list_head *tmp, *tmp2; struct list_head *tmp, *tmp2;
struct octeon_soft_command *sc; struct octeon_soft_command *sc;
octeon_free_sc_zombie_list(oct);
spin_lock_bh(&oct->sc_buf_pool.lock); spin_lock_bh(&oct->sc_buf_pool.lock);
list_for_each_safe(tmp, tmp2, &oct->sc_buf_pool.head) { list_for_each_safe(tmp, tmp2, &oct->sc_buf_pool.head) {
...@@ -824,6 +877,9 @@ struct octeon_soft_command *octeon_alloc_soft_command(struct octeon_device *oct, ...@@ -824,6 +877,9 @@ struct octeon_soft_command *octeon_alloc_soft_command(struct octeon_device *oct,
struct octeon_soft_command *sc = NULL; struct octeon_soft_command *sc = NULL;
struct list_head *tmp; struct list_head *tmp;
if (!rdatasize)
rdatasize = 16;
WARN_ON((offset + datasize + rdatasize + ctxsize) > WARN_ON((offset + datasize + rdatasize + ctxsize) >
SOFT_COMMAND_BUFFER_SIZE); SOFT_COMMAND_BUFFER_SIZE);
......
...@@ -69,6 +69,8 @@ int lio_process_ordered_list(struct octeon_device *octeon_dev, ...@@ -69,6 +69,8 @@ int lio_process_ordered_list(struct octeon_device *octeon_dev,
u32 status; u32 status;
u64 status64; u64 status64;
octeon_free_sc_done_list(octeon_dev);
ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST]; ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST];
do { do {
...@@ -111,26 +113,88 @@ int lio_process_ordered_list(struct octeon_device *octeon_dev, ...@@ -111,26 +113,88 @@ int lio_process_ordered_list(struct octeon_device *octeon_dev,
} }
} }
} }
} else if (force_quit || (sc->timeout && } else if (unlikely(force_quit) || (sc->expiry_time &&
time_after(jiffies, (unsigned long)sc->timeout))) { time_after(jiffies, (unsigned long)sc->expiry_time))) {
dev_err(&octeon_dev->pci_dev->dev, "%s: cmd failed, timeout (%ld, %ld)\n", struct octeon_instr_irh *irh =
__func__, (long)jiffies, (long)sc->timeout); (struct octeon_instr_irh *)&sc->cmd.cmd3.irh;
dev_err(&octeon_dev->pci_dev->dev, "%s: ", __func__);
dev_err(&octeon_dev->pci_dev->dev,
"cmd %x/%x/%llx/%llx failed, ",
irh->opcode, irh->subcode,
sc->cmd.cmd3.ossp[0], sc->cmd.cmd3.ossp[1]);
dev_err(&octeon_dev->pci_dev->dev,
"timeout (%ld, %ld)\n",
(long)jiffies, (long)sc->expiry_time);
status = OCTEON_REQUEST_TIMEOUT; status = OCTEON_REQUEST_TIMEOUT;
} }
if (status != OCTEON_REQUEST_PENDING) { if (status != OCTEON_REQUEST_PENDING) {
sc->sc_status = status;
/* we have received a response or we have timed out */ /* we have received a response or we have timed out */
/* remove node from linked list */ /* remove node from linked list */
list_del(&sc->node); list_del(&sc->node);
atomic_dec(&octeon_dev->response_list atomic_dec(&octeon_dev->response_list
[OCTEON_ORDERED_SC_LIST]. [OCTEON_ORDERED_SC_LIST].
pending_req_count); pending_req_count);
spin_unlock_bh
(&ordered_sc_list->lock);
if (sc->callback) if (!sc->callback) {
atomic_inc(&octeon_dev->response_list
[OCTEON_DONE_SC_LIST].
pending_req_count);
list_add_tail(&sc->node,
&octeon_dev->response_list
[OCTEON_DONE_SC_LIST].head);
if (unlikely(READ_ONCE(sc->caller_is_done))) {
/* caller does not wait for response
* from firmware
*/
if (status != OCTEON_REQUEST_DONE) {
struct octeon_instr_irh *irh;
irh =
(struct octeon_instr_irh *)
&sc->cmd.cmd3.irh;
dev_dbg
(&octeon_dev->pci_dev->dev,
"%s: sc failed: opcode=%x, ",
__func__, irh->opcode);
dev_dbg
(&octeon_dev->pci_dev->dev,
"subcode=%x, ossp[0]=%llx, ",
irh->subcode,
sc->cmd.cmd3.ossp[0]);
dev_dbg
(&octeon_dev->pci_dev->dev,
"ossp[1]=%llx, status=%d\n",
sc->cmd.cmd3.ossp[1],
status);
}
} else {
complete(&sc->complete);
}
spin_unlock_bh(&ordered_sc_list->lock);
} else {
/* sc with callback function */
if (status == OCTEON_REQUEST_TIMEOUT) {
atomic_inc(&octeon_dev->response_list
[OCTEON_ZOMBIE_SC_LIST].
pending_req_count);
list_add_tail(&sc->node,
&octeon_dev->response_list
[OCTEON_ZOMBIE_SC_LIST].
head);
}
spin_unlock_bh(&ordered_sc_list->lock);
sc->callback(octeon_dev, status, sc->callback(octeon_dev, status,
sc->callback_arg); sc->callback_arg);
/* sc is freed by caller */
}
request_complete++; request_complete++;
......
...@@ -53,7 +53,9 @@ enum { ...@@ -53,7 +53,9 @@ enum {
OCTEON_ORDERED_LIST = 0, OCTEON_ORDERED_LIST = 0,
OCTEON_UNORDERED_NONBLOCKING_LIST = 1, OCTEON_UNORDERED_NONBLOCKING_LIST = 1,
OCTEON_UNORDERED_BLOCKING_LIST = 2, OCTEON_UNORDERED_BLOCKING_LIST = 2,
OCTEON_ORDERED_SC_LIST = 3 OCTEON_ORDERED_SC_LIST = 3,
OCTEON_DONE_SC_LIST = 4,
OCTEON_ZOMBIE_SC_LIST = 5
}; };
/** Response Order values for a Octeon Request. */ /** Response Order values for a Octeon Request. */
......
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