// SPDX-License-Identifier: GPL-2.0-only #include #include #include #include #include #include "img_module_iface.h" #include "umac_debugs.h" #include "img_exponential_multi_pools_alloc.h" unsigned int WARN_ON_CNT = 0; unsigned int WARN_ON_ONCE_CNT = 0; unsigned int WARN_ONCE_CNT = 0; unsigned int WARN_CNT = 0; unsigned int BUILD_BUG_ON_CNT = 0; unsigned int BUG_ON_CNT = 0; unsigned int BUG_CNT = 0; DEFINE_MUTEX(ext_ram_access); extern void rate_ctrl_mutex_init(); spinlock_t rcu_read_lock_ipl; DEFINE_MUTEX(rtnl_mutex); void mutex_lock_timedout(SEMAPHORE_T *semaphore, uint32_t testvalue,int32_t timeout) { KRN_testSemaphore(semaphore, testvalue, timeout); } void mutex_lock_timedout_init(SEMAPHORE_T *semaphore, uint32_t value) { KRN_initSemaphore(semaphore, value); } void mutex_unlock_timedout(SEMAPHORE_T *semaphore, uint32_t increment) { KRN_setSemaphore(semaphore, increment); } IRQ_IPL_T raiseIPL(void) { IRQ_IPL_T ret; ret = KRN_raiseIPL(); return ret; } void restoreIPL(IRQ_IPL_T newIPL) { KRN_restoreIPL(newIPL); } void rtnl_lock(void) { mutex_lock(&rtnl_mutex); } void rtnl_unlock(void) { mutex_unlock(&rtnl_mutex); } void osal_init(void) { /* Initialize OSAL related things here */ mutex_init(&rtnl_mutex); rate_ctrl_mutex_init(); mutex_init(&ext_ram_access); } void device_del(struct device *dev) { (void)dev; return; } void put_device(struct device *dev) { (void)dev; return; } int eth_mac_addr(struct net_device *dev, void *p) { (void)dev; (void)p; return 0; } unsigned int readl (void *addr) { return *(unsigned int *)addr; } void writel (unsigned int val, void *addr) { *(volatile unsigned int *)addr = val; return; } int dev_set_name(struct device *dev, const char *fmt, ...) { (void)dev; (void)fmt; return 0; } int ____ilog2_NaN(void) { return 0; } void queue_work(struct workqueue_struct *wq, struct work_struct *work) { int err; IMG_RX_DBG_PARAM_INCR(work_mbox_post, 1); umac_task_post(IMG_MODULE_IFACE_WORK_QUEUE_PORT, work, sizeof(struct work_struct)); } void queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay) { (void)wq; (void)delay; queue_work(wq, (struct work_struct *)dwork); } void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data) { t->func = func; t->data = data; } void send_tasklet_to_mbox(struct tasklet_struct *tasklet); void tasklet_schedule(struct tasklet_struct *t) { send_tasklet_to_mbox(t); } void tasklet_disable(struct tasklet_struct *t) { t->count.counter ++; } void tasklet_enable(struct tasklet_struct *t) { t->count.counter --; } void prandom_bytes(void *buf, int bytes) { unsigned int rand_num; int i = 0; for(i = 0; i < bytes/sizeof(int); i ++) { rand_num = rand(); memcpy(buf + (sizeof(int) * i), &rand_num, sizeof(int)); } if(bytes % sizeof(int)) { rand_num = rand(); memcpy(buf + (sizeof(int) * i), &rand_num, bytes % sizeof(int)); } return; } void init_rwsem(struct rw_semaphore *sem) { KRN_initSemaphore(&sem->sem_lock, 1); return; } /* * lock for writing */ void down_write(struct rw_semaphore *sem) { KRN_testSemaphore(&sem->sem_lock, 1, -1); } /* * release a write lock */ void up_write(struct rw_semaphore *sem) { KRN_setSemaphore(&sem->sem_lock, 1); } /* * lock for reading */ void down_read(struct rw_semaphore *sem) { KRN_testSemaphore(&sem->sem_lock, 1, -1); } /* * release a read lock */ void up_read(struct rw_semaphore *sem) { KRN_setSemaphore(&sem->sem_lock, 1); } /** * complete_all: - signals all threads waiting on this completion * @x: holds the state of this particular completion * * This will wake up all threads waiting on this particular completion event. * * It may be assumed that this function implies a write memory barrier before * changing the task state if and only if any tasks are woken up. */ void complete_all(struct completion *x) { #ifdef MAC80211_TODO unsigned long flags; spin_lock_irqsave(&x->wait.lock, flags); x->done += UINT_MAX/2; __wake_up_locked(&x->wait, TASK_NORMAL, 0); spin_unlock_irqrestore(&x->wait.lock, flags); #else (void)x; // UMAC_TODOMSG("TODO: %s\n", __FUNCTION__); #endif /* MAC80211_TODO */ } /** * wait_for_completion_interruptible: - waits for completion of a task (w/intr) * @x: holds the state of this particular completion * * This waits for completion of a specific task to be signaled. It is * interruptible. * * Return: -ERESTARTSYS if interrupted, 0 if completed. */ int wait_for_completion_interruptible(struct completion *x) { #ifdef MAC80211_TODO long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); if (t == -ERESTARTSYS) return t; return 0; #else (void)x; // UMAC_TODOMSG("TODO: %s\n", __FUNCTION__); return 0; #endif /* MAC80211_TODO */ } /** * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr)) * @x: holds the state of this particular completion * @timeout: timeout value in jiffies * * This waits for either a completion of a specific task to be signaled or for a * specified timeout to expire. It is interruptible. The timeout is in jiffies. * * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1, * or number of jiffies left till timeout) if completed. */ long wait_for_completion_interruptible_timeout(struct completion *x, unsigned long timeout) { #ifdef MAC80211_TODO return wait_for_common(x, timeout, TASK_INTERRUPTIBLE); #else (void)x; (void)timeout; // UMAC_TODOMSG("TODO: %s\n", __FUNCTION__); return 1; #endif /* MAC80211_TODO */ } /** * simple_strtol - convert a string to a signed long * @cp: The start of the string * @endp: A pointer to the end of the parsed string will be placed here * @base: The number base to use * * This function is obsolete. Please use kstrtol instead. */ long simple_strtol(const char *cp, char **endp, unsigned int base) { #ifdef MAC80211_TODO if (*cp == '-') return -simple_strtoul(cp + 1, endp, base); return simple_strtoul(cp, endp, base); #else (void)cp; (void)endp; (void)base; UMAC_TODOMSG("TODO: %s\n", __FUNCTION__); return 1; #endif /* MAC80211_TODO */ } unsigned int thread_ret; void * kthread_run(int (*func)(void *data), void *data, void *str) { (void)str; if(func) { func(data); } return &thread_ret; } /* a perfect nop */ int alg_test(const char *driver, const char *alg, u32 type, u32 mask) { (void)driver; (void)alg; (void)type; (void)mask; return 0; } void get_random_bytes(void *buf, int nbytes) { unsigned int rand_num; int i = 0; for(i = 0; i < nbytes/sizeof(int); i ++) { rand_num = rand(); memcpy(buf + (sizeof(int) * i), &rand_num, sizeof(int)); } if(nbytes % sizeof(int)) { rand_num = rand(); memcpy(buf + (sizeof(int) * i), &rand_num, nbytes % sizeof(int)); } return; } unsigned int prandom_u32() { return rand(); } void osal_start_task(void *task_func, task_t *task, uint32_t *task_stack, int stack_size, int task_priority, void *parameter, const char *task_name) { KRN_startTask(task_func, task, task_stack, stack_size, task_priority, parameter, task_name); } void osal_remove_task( task_t *task ) { KRN_removeTask(task); } void img_umac_lock_ext_ram_access() { mutex_lock(&ext_ram_access); } void img_umac_unlock_ext_ram_access() { mutex_unlock(&ext_ram_access); } unsigned int img_umac_ext_ram_access_addr(unsigned int addr_64bit) { unsigned int msb_value; unsigned int ext_addr; msb_value = (addr_64bit>>25) & 0x7FFF; UCC_WRITE32(ABS_SYS_UCCP_SOC_FAB_MEM_ADDR_MSBS0, (unsigned int)msb_value); UCC_WRITE32(ABS_SYS_UCCP_SOC_FAB_MEM_ADDR_MSBS1, (unsigned int)msb_value); ext_addr =(((unsigned int)addr_64bit & 0x01ffffff)|0xb0000000); return ext_addr; }