rsi: Adding core and main files
PATCH v3 3/10 rsi: Adding core and main files
From: Fariya Fatima
This patch adds the files which contain functionality related to initialization, queuing and de-queuing of packets to be sent to the device, sending and receiving packets from the device and OS interface operations.
---
rsi_91x_core.c | 345 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rsi_91x_main.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 616 insertions(+)
drivers/net/wireless/rsi/rsi_91x_core.c +345 -0
@@ -0,0 +1,345 @@ +/** +* Copyright (c) 2014 Redpine Signals Inc. +* +* Permission to use, copy, modify, and/or distribute this software for any +* purpose with or without fee is hereby granted, provided that the above +* copyright notice and this permission notice appear in all copies. +* +* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "rsi_mgmt.h" +#include "rsi_common.h" + +/** +* This function determines the queue with the min weight. +* +* @param common Pointer to the driver private structure. +* @return q_num: Corresponding queue number. +*/ +static u8 rsi_determine_min_weight_queue (struct rsi_common *common) +{ +struct wmm_qinfo *tx_qinfo = common->tx_qinfo; +u32 q_len =0 ; +u8 ii =0 ; + +for (ii =0 ; ii <NUM_EDCA_QUEUES ; ii++) { + q_len =skb_queue_len (&common->tx_queue[ii]); +if ((tx_qinfo[ii].pkt_contended) && q_len) { + common->min_weight = tx_qinfo[ii].weight; +break ; + } + } +return ii; +} + +/** +* This function recalculates the weights corresponding to each queue. +* +* @param common Pointer to the driver private structure. +* @return recontend_queue bool variable +*/ +static bool rsi_recalculate_weights (struct rsi_common *common) +{ +struct wmm_qinfo *tx_qinfo = common->tx_qinfo; +bool recontend_queue = false; +u8 ii =0 ; +u32 q_len =0 ; + +for (ii =0 ; ii <NUM_EDCA_QUEUES ; ii++) { + q_len =skb_queue_len (&common->tx_queue[ii]); +/* Check for the need of contention */ +if (q_len) { +if (tx_qinfo[ii].pkt_contended) { + tx_qinfo[ii].weight = + ((tx_qinfo[ii].weight > common->min_weight) ? + tx_qinfo[ii].weight - common->min_weight :0 ); + }else { + tx_qinfo[ii].pkt_contended =1 ; + tx_qinfo[ii].weight = tx_qinfo[ii].wme_params; + recontend_queue = true; + } + }else {/* No packets so no contention */ + tx_qinfo[ii].weight =0 ; + tx_qinfo[ii].pkt_contended =0 ; + } + } + +return recontend_queue; +} + +/** +* This function determines the queue from which packet +* has to be dequeued. +* +* @param common Pointer to the driver private structure. +* @return q_num: Corresponding queue number on success. +*/ +static u8 rsi_core_determine_hal_queue (struct rsi_common *common) +{ +bool recontend_queue = false; +u32 q_len =0 ; +u8 q_num =INVALID_QUEUE ; +u8 ii, min =0 ; + +if (skb_queue_len (&common->tx_queue[MGMT_SOFT_Q ])) { +if (!common->mgmt_q_block) + q_num =MGMT_SOFT_Q ; +return q_num; + } + +if (common->pkt_cnt !=0 ) { + --common->pkt_cnt; +return common->selected_qnum; + } + +get_queue_num: + q_num =0 ; + recontend_queue = false; + + q_num =rsi_determine_min_weight_queue (common); + q_len =skb_queue_len (&common->tx_queue[ii]); + ii = q_num; + +/* Selecting the queue with least back off */ +for (; ii <NUM_EDCA_QUEUES ; ii++) { +if (((common->tx_qinfo[ii].pkt_contended) && + (common->tx_qinfo[ii].weight < min)) && q_len) { + min = common->tx_qinfo[ii].weight; + q_num = ii; + } + } + + common->tx_qinfo[q_num].pkt_contended =0 ; +/* Adjust the back off values for all queues again */ + recontend_queue =rsi_recalculate_weights (common); + + q_len =skb_queue_len (&common->tx_queue[q_num]); +if (!q_len) { +/* If any queues are freshly contended and the selected queue +* doesn't have any packets +* then get the queue number again with fresh values +*/ +if (recontend_queue) + goto get_queue_num; + + q_num =INVALID_QUEUE ; +return q_num; + } + + common->selected_qnum = q_num; + q_len =skb_queue_len (&common->tx_queue[q_num]); + +switch (common->selected_qnum) { +case VO_Q : +if (q_len >MAX_CONTINUOUS_VO_PKTS ) + common->pkt_cnt = (MAX_CONTINUOUS_VO_PKTS -1 ); +else + common->pkt_cnt = --q_len; +break ; + +case VI_Q : +if (q_len >MAX_CONTINUOUS_VI_PKTS ) + common->pkt_cnt = (MAX_CONTINUOUS_VI_PKTS -1 ); +else + common->pkt_cnt = --q_len; + +break ; + +default : + common->pkt_cnt =0 ; +break ; + } + +return q_num; +} + +/** +* This functions enqueues the packet to the queue specified +* by the queue number. +* +* @param common Pointer to the driver private structure. +* @param skb Pointer to the socket buffer structure. +* @return None. +*/ +static void rsi_core_queue_pkt (struct rsi_common *common, +struct sk_buff *skb) +{ +u8 q_num = skb->priority; +if (q_num >=NUM_SOFT_QUEUES ) { +rsi_dbg (ERR_ZONE ,"%s: Invalid Queue Number: q_num = %d\n" , + __func__, q_num); +dev_kfree_skb (skb); +return ; + } + +skb_queue_tail (&common->tx_queue[q_num], skb); +return ; +} + +/** +* This functions dequeues the packet from the queue specified by +* the queue number. +* +* @param common Pointer to the driver private structure. +* @param q_num Queue number. +* @return Pointer to sk_buff structure. +*/ +static struct sk_buff *rsi_core_dequeue_pkt (struct rsi_common *common, +u8 q_num) +{ +if (q_num >=NUM_SOFT_QUEUES ) { +rsi_dbg (ERR_ZONE ,"%s: Invalid Queue Number: q_num = %d\n" , + __func__, q_num); +return NULL ; + } + +return skb_dequeue (&common->tx_queue[q_num]); +} + +/** +* This function is used to determine the wmm queue based on the backoff +* procedure. Data packets are dequeued from the selected hal queue and +* sent to the below layers. +* +* @param common Pointer to the driver private structure. +* @return None. +*/ +void rsi_core_qos_processor (struct rsi_common *common) +{ +struct rsi_hw *adapter = common->priv; +struct sk_buff *skb; +unsigned long tstamp_1, tstamp_2; +u8 q_num; +int status; + + tstamp_1 = jiffies; +while (1 ) { + q_num =rsi_core_determine_hal_queue (common); +rsi_dbg (DATA_TX_ZONE , +"%s: Queue number = %d\n" , __func__, q_num); + +if (q_num ==INVALID_QUEUE ) { +rsi_dbg (DATA_TX_ZONE ,"%s: No More Pkt\n" , __func__); +break ; + } + +mutex_lock (&common->tx_rxlock); + + status = adapter->check_hw_queue_status (adapter, q_num); +if ((status <=0 )) { +mutex_unlock (&common->tx_rxlock); +break ; + } + +if ((q_num <MGMT_SOFT_Q ) && + ((skb_queue_len (&common->tx_queue[q_num])) <= +MIN_DATA_QUEUE_WATER_MARK )) { +if (ieee80211_queue_stopped (adapter->hw,WME_AC (q_num))) +ieee80211_wake_queue (adapter->hw, +WME_AC (q_num)); + } + + skb =rsi_core_dequeue_pkt (common, q_num); +if (skb ==NULL ) { +mutex_unlock (&common->tx_rxlock); +break ; + } + +if (q_num ==MGMT_SOFT_Q ) + status =rsi_send_mgmt_pkt (common, skb); +else + status =rsi_send_data_pkt (common, skb); + +if (status) { +mutex_unlock (&common->tx_rxlock); +break ; + } + + common->tx_stats.total_tx_pkt_send[q_num]++; + + tstamp_2 = jiffies; +mutex_unlock (&common->tx_rxlock); + +if (tstamp_2 > tstamp_1 + (300 *HZ /1000 )) +schedule (); + } +return ; +} + +/** +* This function transmits the packets received from mac80211. +* +* @param common Pointer to the driver private structure. +* @param skb Pointer to the socket buffer structure. +* @return 0 on success, -1 on failure. +*/ +int rsi_core_xmit (struct rsi_common *common,struct sk_buff *skb) +{ +struct rsi_hw *adapter = common->priv; +struct ieee80211_tx_info *info; +struct skb_info *tx_params; +u8 q_num, frame_type, tid =0 ; +u16 fc =0 ; + +if ((!skb) || (!skb->len)) { +rsi_dbg (ERR_ZONE ,"%s: Null skb/zero Length packet\n" , + __func__); + goto xmit_fail; + } + info =IEEE80211_SKB_CB (skb); + tx_params = (struct skb_info *)info->driver_data; + +if (common->fsm_state !=FSM_MAC_INIT_DONE ) { +rsi_dbg (ERR_ZONE ,"%s: FSM state not open\n" , __func__); + goto xmit_fail; + } + + frame_type = (skb->data[0 ] &0x0f ); + fc = *((u16 *)&skb->data[MAC_80211_HDR_FRAME_CONTROL ]); + +if ((frame_type ==IEEE80211_MGMT_FRAME ) || + (frame_type ==IEEE80211_CTL_FRAME )) { + q_num =MGMT_SOFT_Q ; + skb->priority = q_num; + }else { +if (fc &IEEE80211_STYPE_QOS_DATA ) { + tid = (skb->data[24 ] &IEEE80211_QOS_TID ); +pr_info ("going in qos_data check\n" ); + skb->priority =TID_TO_WME_AC (tid); + }else { + tid =IEEE80211_NONQOS_TID ; + skb->priority =BE_Q ; + } + q_num = skb->priority; + tx_params->tid = tid; + tx_params->sta_id =0 ; + } + +if ((q_num !=MGMT_SOFT_Q ) && + ((skb_queue_len (&common->tx_queue[q_num]) +1 ) >= +DATA_QUEUE_WATER_MARK )) { +if (!ieee80211_queue_stopped (adapter->hw,WME_AC (q_num))) +ieee80211_stop_queue (adapter->hw,WME_AC (q_num)); +rsi_set_event (&common->tx_thread.event); + goto xmit_fail; + } + +rsi_core_queue_pkt (common, skb); +rsi_dbg (DATA_TX_ZONE ,"%s: ===> Scheduling TX thead <===\n" , __func__); +rsi_set_event (&common->tx_thread.event); + +return 0 ; + +xmit_fail: +rsi_dbg (ERR_ZONE ,"%s: Failed to queue packet\n" , __func__); +if (skb) +dev_kfree_skb (skb); +return -1 ; +}
drivers/net/wireless/rsi/rsi_91x_main.c +271 -0
271 lines not on this page · raw message
Quoted 1 line · Fariya Fatima
From: Fariya Fatima
Btw, From: should also have an email address.
drivers/net/wireless/rsi/rsi_91x_core.c line 305
Quoted 2 lines
drivers/net/wireless/rsi/rsi_91x_core.c +2
-0+ frame_type = (skb->data[0 ] &0x0f ); + fc = *((u16 *)&skb->data[MAC_80211_HDR_FRAME_CONTROL ]);
That's not endian safe. you should typecast to a struct instead and probably use the inlines from ieee80211.h instead of
drivers/net/wireless/rsi/rsi_91x_core.c line 308
Quoted 2 lines
drivers/net/wireless/rsi/rsi_91x_core.c +2
-0+if ((frame_type ==IEEE80211_MGMT_FRAME ) || + (frame_type ==IEEE80211_CTL_FRAME )) {
^ that. You also forgot the masking.
drivers/net/wireless/rsi/rsi_91x_core.c line 312
Quoted 2 lines
drivers/net/wireless/rsi/rsi_91x_core.c +2
-0+ }else { +if (fc &IEEE80211_STYPE_QOS_DATA ) {
There's an inline for that too. fc should be __le16. Also you don't need to init it, in fact don't so the compiler will warn you if you don't do it in some code path.
drivers/net/wireless/rsi/rsi_91x_core.c line 319
Quoted 7 lines
drivers/net/wireless/rsi/rsi_91x_core.c +7
-0+ tid = (skb->data[24 ] &IEEE80211_QOS_TID ); +pr_info ("going in qos_data check\n" ); + skb->priority =TID_TO_WME_AC (tid); + }else { + tid =IEEE80211_NONQOS_TID ; + skb->priority =BE_Q ; + }
mac80211 sets and uses skb->priority, so this might not be a good idea.
Review
Quoted 1 line
(quoted diff) +1
-0+ return -1;
again -1, not sure where it ends up getting used but a proper error code would be better.
drivers/net/wireless/rsi/rsi_91x_main.c line 56
Quoted 4 lines
drivers/net/wireless/rsi/rsi_91x_main.c +4
-0+if (!pkt_len) { +rsi_dbg (ERR_ZONE ,"%s: Dummy pkt has come in\n" , __func__); +BUG_ON (1 ); + }
No need for BUG_ON, just do
if (WARN(!pkt_len, "Dummy packet..."))
return NULL;
or so.
Quoted 2 lines
+/**
+ * This function initializes os interface operations.
That sounds like some sort of OS abstraction, but doesn't really seem to be one? Maybe it should have a different name.
Review
Quoted 2 lines
(quoted diff) +2
-0+ return; +}
naked return statements are useless.
drivers/net/wireless/rsi/rsi_91x_main.c line 262
Quoted 4 lines
drivers/net/wireless/rsi/rsi_91x_main.c +4
-0+static void rsi_91x_hal_module_exit (void ) +{ +rsi_dbg (INIT_ZONE ,"%s: Module exit called\n" , __func__); +return ;
ditto
johannes
Quoted 12 lines · Fariya Fatima
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Quoted 1 line
+MODULE_LICENSE("GPL");
That's not GPL actually.
johannes
Quoted 1 line · Fariya Fatima
+ * @return 0 on success, -1 on failure.
The function should be void, you don't use its return value, nor would that make sense.
drivers/net/wireless/rsi/rsi_91x_core.c line 343
Quoted 4 lines
drivers/net/wireless/rsi/rsi_91x_core.c +4
-0+xmit_fail: +rsi_dbg (ERR_ZONE ,"%s: Failed to queue packet\n" , __func__); +if (skb) +dev_kfree_skb (skb);
You need to use the mac80211 free function for xmit skbs.
johannes