162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Copyright (c) 2021, MediaTek Inc. 462306a36Sopenharmony_ci * Copyright (c) 2021-2022, Intel Corporation. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Authors: 762306a36Sopenharmony_ci * Haijun Liu <haijun.liu@mediatek.com> 862306a36Sopenharmony_ci * Moises Veleta <moises.veleta@intel.com> 962306a36Sopenharmony_ci * Ricardo Martinez <ricardo.martinez@linux.intel.com> 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * Contributors: 1262306a36Sopenharmony_ci * Amir Hanania <amir.hanania@intel.com> 1362306a36Sopenharmony_ci * Andy Shevchenko <andriy.shevchenko@linux.intel.com> 1462306a36Sopenharmony_ci * Chandrashekar Devegowda <chandrashekar.devegowda@intel.com> 1562306a36Sopenharmony_ci * Eliot Lee <eliot.lee@intel.com> 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#ifndef __T7XX_PORT_H__ 1962306a36Sopenharmony_ci#define __T7XX_PORT_H__ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#include <linux/bits.h> 2262306a36Sopenharmony_ci#include <linux/device.h> 2362306a36Sopenharmony_ci#include <linux/mutex.h> 2462306a36Sopenharmony_ci#include <linux/sched.h> 2562306a36Sopenharmony_ci#include <linux/skbuff.h> 2662306a36Sopenharmony_ci#include <linux/spinlock.h> 2762306a36Sopenharmony_ci#include <linux/types.h> 2862306a36Sopenharmony_ci#include <linux/wait.h> 2962306a36Sopenharmony_ci#include <linux/wwan.h> 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include "t7xx_hif_cldma.h" 3262306a36Sopenharmony_ci#include "t7xx_pci.h" 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define PORT_CH_ID_MASK GENMASK(7, 0) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* Channel ID and Message ID definitions. 3762306a36Sopenharmony_ci * The channel number consists of peer_id(15:12) , channel_id(11:0) 3862306a36Sopenharmony_ci * peer_id: 3962306a36Sopenharmony_ci * 0:reserved, 1: to AP, 2: to MD 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_cienum port_ch { 4262306a36Sopenharmony_ci /* to AP */ 4362306a36Sopenharmony_ci PORT_CH_AP_CONTROL_RX = 0x1000, 4462306a36Sopenharmony_ci PORT_CH_AP_CONTROL_TX = 0x1001, 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci /* to MD */ 4762306a36Sopenharmony_ci PORT_CH_CONTROL_RX = 0x2000, 4862306a36Sopenharmony_ci PORT_CH_CONTROL_TX = 0x2001, 4962306a36Sopenharmony_ci PORT_CH_UART1_RX = 0x2006, /* META */ 5062306a36Sopenharmony_ci PORT_CH_UART1_TX = 0x2008, 5162306a36Sopenharmony_ci PORT_CH_UART2_RX = 0x200a, /* AT */ 5262306a36Sopenharmony_ci PORT_CH_UART2_TX = 0x200c, 5362306a36Sopenharmony_ci PORT_CH_MD_LOG_RX = 0x202a, /* MD logging */ 5462306a36Sopenharmony_ci PORT_CH_MD_LOG_TX = 0x202b, 5562306a36Sopenharmony_ci PORT_CH_LB_IT_RX = 0x203e, /* Loop back test */ 5662306a36Sopenharmony_ci PORT_CH_LB_IT_TX = 0x203f, 5762306a36Sopenharmony_ci PORT_CH_STATUS_RX = 0x2043, /* Status events */ 5862306a36Sopenharmony_ci PORT_CH_MIPC_RX = 0x20ce, /* MIPC */ 5962306a36Sopenharmony_ci PORT_CH_MIPC_TX = 0x20cf, 6062306a36Sopenharmony_ci PORT_CH_MBIM_RX = 0x20d0, 6162306a36Sopenharmony_ci PORT_CH_MBIM_TX = 0x20d1, 6262306a36Sopenharmony_ci PORT_CH_DSS0_RX = 0x20d2, 6362306a36Sopenharmony_ci PORT_CH_DSS0_TX = 0x20d3, 6462306a36Sopenharmony_ci PORT_CH_DSS1_RX = 0x20d4, 6562306a36Sopenharmony_ci PORT_CH_DSS1_TX = 0x20d5, 6662306a36Sopenharmony_ci PORT_CH_DSS2_RX = 0x20d6, 6762306a36Sopenharmony_ci PORT_CH_DSS2_TX = 0x20d7, 6862306a36Sopenharmony_ci PORT_CH_DSS3_RX = 0x20d8, 6962306a36Sopenharmony_ci PORT_CH_DSS3_TX = 0x20d9, 7062306a36Sopenharmony_ci PORT_CH_DSS4_RX = 0x20da, 7162306a36Sopenharmony_ci PORT_CH_DSS4_TX = 0x20db, 7262306a36Sopenharmony_ci PORT_CH_DSS5_RX = 0x20dc, 7362306a36Sopenharmony_ci PORT_CH_DSS5_TX = 0x20dd, 7462306a36Sopenharmony_ci PORT_CH_DSS6_RX = 0x20de, 7562306a36Sopenharmony_ci PORT_CH_DSS6_TX = 0x20df, 7662306a36Sopenharmony_ci PORT_CH_DSS7_RX = 0x20e0, 7762306a36Sopenharmony_ci PORT_CH_DSS7_TX = 0x20e1, 7862306a36Sopenharmony_ci}; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cistruct t7xx_port; 8162306a36Sopenharmony_cistruct port_ops { 8262306a36Sopenharmony_ci int (*init)(struct t7xx_port *port); 8362306a36Sopenharmony_ci int (*recv_skb)(struct t7xx_port *port, struct sk_buff *skb); 8462306a36Sopenharmony_ci void (*md_state_notify)(struct t7xx_port *port, unsigned int md_state); 8562306a36Sopenharmony_ci void (*uninit)(struct t7xx_port *port); 8662306a36Sopenharmony_ci int (*enable_chl)(struct t7xx_port *port); 8762306a36Sopenharmony_ci int (*disable_chl)(struct t7xx_port *port); 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistruct t7xx_port_conf { 9162306a36Sopenharmony_ci enum port_ch tx_ch; 9262306a36Sopenharmony_ci enum port_ch rx_ch; 9362306a36Sopenharmony_ci unsigned char txq_index; 9462306a36Sopenharmony_ci unsigned char rxq_index; 9562306a36Sopenharmony_ci unsigned char txq_exp_index; 9662306a36Sopenharmony_ci unsigned char rxq_exp_index; 9762306a36Sopenharmony_ci enum cldma_id path_id; 9862306a36Sopenharmony_ci struct port_ops *ops; 9962306a36Sopenharmony_ci char *name; 10062306a36Sopenharmony_ci enum wwan_port_type port_type; 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistruct t7xx_port { 10462306a36Sopenharmony_ci /* Members not initialized in definition */ 10562306a36Sopenharmony_ci const struct t7xx_port_conf *port_conf; 10662306a36Sopenharmony_ci struct t7xx_pci_dev *t7xx_dev; 10762306a36Sopenharmony_ci struct device *dev; 10862306a36Sopenharmony_ci u16 seq_nums[2]; /* TX/RX sequence numbers */ 10962306a36Sopenharmony_ci atomic_t usage_cnt; 11062306a36Sopenharmony_ci struct list_head entry; 11162306a36Sopenharmony_ci struct list_head queue_entry; 11262306a36Sopenharmony_ci /* TX and RX flows are asymmetric since ports are multiplexed on 11362306a36Sopenharmony_ci * queues. 11462306a36Sopenharmony_ci * 11562306a36Sopenharmony_ci * TX: data blocks are sent directly to a queue. Each port 11662306a36Sopenharmony_ci * does not maintain a TX list; instead, they only provide 11762306a36Sopenharmony_ci * a wait_queue_head for blocking writes. 11862306a36Sopenharmony_ci * 11962306a36Sopenharmony_ci * RX: Each port uses a RX list to hold packets, 12062306a36Sopenharmony_ci * allowing the modem to dispatch RX packet as quickly as possible. 12162306a36Sopenharmony_ci */ 12262306a36Sopenharmony_ci struct sk_buff_head rx_skb_list; 12362306a36Sopenharmony_ci spinlock_t port_update_lock; /* Protects port configuration */ 12462306a36Sopenharmony_ci wait_queue_head_t rx_wq; 12562306a36Sopenharmony_ci int rx_length_th; 12662306a36Sopenharmony_ci bool chan_enable; 12762306a36Sopenharmony_ci struct task_struct *thread; 12862306a36Sopenharmony_ci union { 12962306a36Sopenharmony_ci struct { 13062306a36Sopenharmony_ci struct wwan_port *wwan_port; 13162306a36Sopenharmony_ci } wwan; 13262306a36Sopenharmony_ci struct { 13362306a36Sopenharmony_ci struct rchan *relaych; 13462306a36Sopenharmony_ci } log; 13562306a36Sopenharmony_ci }; 13662306a36Sopenharmony_ci}; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cistruct sk_buff *t7xx_port_alloc_skb(int payload); 13962306a36Sopenharmony_cistruct sk_buff *t7xx_ctrl_alloc_skb(int payload); 14062306a36Sopenharmony_ciint t7xx_port_enqueue_skb(struct t7xx_port *port, struct sk_buff *skb); 14162306a36Sopenharmony_ciint t7xx_port_send_skb(struct t7xx_port *port, struct sk_buff *skb, unsigned int pkt_header, 14262306a36Sopenharmony_ci unsigned int ex_msg); 14362306a36Sopenharmony_ciint t7xx_port_send_ctl_skb(struct t7xx_port *port, struct sk_buff *skb, unsigned int msg, 14462306a36Sopenharmony_ci unsigned int ex_msg); 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci#endif /* __T7XX_PORT_H__ */ 147