/** @brief check the free space in a SBD RB @param rb the pointer to an SBD RB instance @retval "> 0" the size of free space in the @b @@dev TXQ @retval "< 0" an error code */ static inline int check_rb_space(struct sbd_ring_buffer *rb, unsigned int qlen, unsigned int in, unsigned int out) { unsigned int space; if (!circ_valid(qlen, in, out)) { mif_err("ERR! TXQ[%d:%d] DIRTY (qlen:%d in:%d out:%d)\n", rb->id, rb->ch, qlen, in, out); return -EIO; } space = circ_get_space(qlen, in, out); if (unlikely(space < 1)) { mif_err_limited("TXQ[%d:%d] NOSPC (qlen:%d in:%d out:%d)\n", rb->id, rb->ch, qlen, in, out); return -ENOSPC; } return space; }
/** @brief check the free space in a circular TXQ @param mld the pointer to a mem_link_device instance @param dev the pointer to a mem_ipc_device instance @param qsize the size of the buffer in @b @@dev TXQ @param in the IN (HEAD) pointer value of the TXQ @param out the OUT (TAIL) pointer value of the TXQ @param count the size of the data to be transmitted @retval "> 0" the size of free space in the @b @@dev TXQ @retval "< 0" an error code */ static inline int check_txq_space(struct mem_link_device *mld, struct mem_ipc_device *dev, unsigned int qsize, unsigned int in, unsigned int out, unsigned int count) { struct link_device *ld = &mld->link_dev; struct modem_ctl *mc = ld->mc; unsigned int usage; unsigned int space; if (!circ_valid(qsize, in, out)) { mif_err("%s: ERR! Invalid %s_TXQ{qsize:%d in:%d out:%d}\n", ld->name, dev->name, qsize, in, out); return -EIO; } usage = circ_get_usage(qsize, in, out); if (unlikely(usage > SHM_UL_USAGE_LIMIT) && cp_online(mc)) { #ifdef DEBUG_MODEM_IF mif_debug("%s: CAUTION! BUSY in %s_TXQ{qsize:%d in:%d out:%d "\ "usage:%d (count:%d)}\n", ld->name, dev->name, qsize, in, out, usage, count); #endif return -EBUSY; } space = circ_get_space(qsize, in, out); if (unlikely(space < count)) { #ifdef DEBUG_MODEM_IF if (cp_online(mc)) { mif_err("%s: CAUTION! NOSPC in %s_TXQ{qsize:%d in:%d "\ "out:%d space:%d count:%d}\n", ld->name, dev->name, qsize, in, out, space, count); } #endif return -ENOSPC; } return space; }
static inline int check_udl_space(struct mem_link_device *mld, struct mem_ipc_device *dev, unsigned int qsize, unsigned int in, unsigned int out, unsigned int count) { struct link_device *ld = &mld->link_dev; unsigned int space; if (!circ_valid(qsize, in, out)) { mif_err("%s: ERR! Invalid %s_TXQ{qsize:%d in:%d out:%d}\n", ld->name, dev->name, qsize, in, out); return -EIO; } space = circ_get_space(qsize, in, out); if (unlikely(space < count)) { mif_err("%s: NOSPC in %s_TXQ{qsize:%d in:%d " "out:%d space:%d count:%d}\n", ld->name, dev->name, qsize, in, out, space, count); return -ENOSPC; } return 0; }