qos.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <net/dsa.h>
  3. #include <linux/delay.h>
  4. #include <asm/mach-rtl838x/mach-rtl83xx.h>
  5. #include "rtl83xx.h"
  6. static struct rtl838x_switch_priv *switch_priv;
  7. extern struct rtl83xx_soc_info soc_info;
  8. enum scheduler_type {
  9. WEIGHTED_FAIR_QUEUE = 0,
  10. WEIGHTED_ROUND_ROBIN,
  11. };
  12. int max_available_queue[] = {0, 1, 2, 3, 4, 5, 6, 7};
  13. int default_queue_weights[] = {1, 1, 1, 1, 1, 1, 1, 1};
  14. int dot1p_priority_remapping[] = {0, 1, 2, 3, 4, 5, 6, 7};
  15. static void rtl839x_read_scheduling_table(int port)
  16. {
  17. u32 cmd = 1 << 9 /* Execute cmd */
  18. | 0 << 8 /* Read */
  19. | 0 << 6 /* Table type 0b00 */
  20. | (port & 0x3f);
  21. rtl839x_exec_tbl2_cmd(cmd);
  22. }
  23. static void rtl839x_write_scheduling_table(int port)
  24. {
  25. u32 cmd = 1 << 9 /* Execute cmd */
  26. | 1 << 8 /* Write */
  27. | 0 << 6 /* Table type 0b00 */
  28. | (port & 0x3f);
  29. rtl839x_exec_tbl2_cmd(cmd);
  30. }
  31. static void rtl839x_read_out_q_table(int port)
  32. {
  33. u32 cmd = 1 << 9 /* Execute cmd */
  34. | 0 << 8 /* Read */
  35. | 2 << 6 /* Table type 0b10 */
  36. | (port & 0x3f);
  37. rtl839x_exec_tbl2_cmd(cmd);
  38. }
  39. static void rtl838x_storm_enable(struct rtl838x_switch_priv *priv, int port, bool enable)
  40. {
  41. // Enable Storm control for that port for UC, MC, and BC
  42. if (enable)
  43. sw_w32(0x7, RTL838X_STORM_CTRL_LB_CTRL(port));
  44. else
  45. sw_w32(0x0, RTL838X_STORM_CTRL_LB_CTRL(port));
  46. }
  47. u32 rtl838x_get_egress_rate(struct rtl838x_switch_priv *priv, int port)
  48. {
  49. u32 rate;
  50. if (port > priv->cpu_port)
  51. return 0;
  52. rate = sw_r32(RTL838X_SCHED_P_EGR_RATE_CTRL(port)) & 0x3fff;
  53. return rate;
  54. }
  55. /* Sets the rate limit, 10MBit/s is equal to a rate value of 625 */
  56. int rtl838x_set_egress_rate(struct rtl838x_switch_priv *priv, int port, u32 rate)
  57. {
  58. u32 old_rate;
  59. if (port > priv->cpu_port)
  60. return -1;
  61. old_rate = sw_r32(RTL838X_SCHED_P_EGR_RATE_CTRL(port));
  62. sw_w32(rate, RTL838X_SCHED_P_EGR_RATE_CTRL(port));
  63. return old_rate;
  64. }
  65. /* Set the rate limit for a particular queue in Bits/s
  66. * units of the rate is 16Kbps
  67. */
  68. void rtl838x_egress_rate_queue_limit(struct rtl838x_switch_priv *priv, int port,
  69. int queue, u32 rate)
  70. {
  71. if (port > priv->cpu_port)
  72. return;
  73. if (queue > 7)
  74. return;
  75. sw_w32(rate, RTL838X_SCHED_Q_EGR_RATE_CTRL(port, queue));
  76. }
  77. static void rtl838x_rate_control_init(struct rtl838x_switch_priv *priv)
  78. {
  79. int i;
  80. pr_info("Enabling Storm control\n");
  81. // TICK_PERIOD_PPS
  82. if (priv->id == 0x8380)
  83. sw_w32_mask(0x3ff << 20, 434 << 20, RTL838X_SCHED_LB_TICK_TKN_CTRL_0);
  84. // Set burst rate
  85. sw_w32(0x00008000, RTL838X_STORM_CTRL_BURST_0); // UC
  86. sw_w32(0x80008000, RTL838X_STORM_CTRL_BURST_1); // MC and BC
  87. // Set burst Packets per Second to 32
  88. sw_w32(0x00000020, RTL838X_STORM_CTRL_BURST_PPS_0); // UC
  89. sw_w32(0x00200020, RTL838X_STORM_CTRL_BURST_PPS_1); // MC and BC
  90. // Include IFG in storm control, rate based on bytes/s (0 = packets)
  91. sw_w32_mask(0, 1 << 6 | 1 << 5, RTL838X_STORM_CTRL);
  92. // Bandwidth control includes preamble and IFG (10 Bytes)
  93. sw_w32_mask(0, 1, RTL838X_SCHED_CTRL);
  94. // On SoCs except RTL8382M, set burst size of port egress
  95. if (priv->id != 0x8382)
  96. sw_w32_mask(0xffff, 0x800, RTL838X_SCHED_LB_THR);
  97. /* Enable storm control on all ports with a PHY and limit rates,
  98. * for UC and MC for both known and unknown addresses */
  99. for (i = 0; i < priv->cpu_port; i++) {
  100. if (priv->ports[i].phy) {
  101. sw_w32((1 << 18) | 0x8000, RTL838X_STORM_CTRL_PORT_UC(i));
  102. sw_w32((1 << 18) | 0x8000, RTL838X_STORM_CTRL_PORT_MC(i));
  103. sw_w32(0x8000, RTL838X_STORM_CTRL_PORT_BC(i));
  104. rtl838x_storm_enable(priv, i, true);
  105. }
  106. }
  107. // Attack prevention, enable all attack prevention measures
  108. //sw_w32(0x1ffff, RTL838X_ATK_PRVNT_CTRL);
  109. /* Attack prevention, drop (bit = 0) problematic packets on all ports.
  110. * Setting bit = 1 means: trap to CPU
  111. */
  112. //sw_w32(0, RTL838X_ATK_PRVNT_ACT);
  113. // Enable attack prevention on all ports
  114. //sw_w32(0x0fffffff, RTL838X_ATK_PRVNT_PORT_EN);
  115. }
  116. /* Sets the rate limit, 10MBit/s is equal to a rate value of 625 */
  117. u32 rtl839x_get_egress_rate(struct rtl838x_switch_priv *priv, int port)
  118. {
  119. u32 rate;
  120. pr_debug("%s: Getting egress rate on port %d to %d\n", __func__, port, rate);
  121. if (port >= priv->cpu_port)
  122. return 0;
  123. mutex_lock(&priv->reg_mutex);
  124. rtl839x_read_scheduling_table(port);
  125. rate = sw_r32(RTL839X_TBL_ACCESS_DATA_2(7));
  126. rate <<= 12;
  127. rate |= sw_r32(RTL839X_TBL_ACCESS_DATA_2(8)) >> 20;
  128. mutex_unlock(&priv->reg_mutex);
  129. return rate;
  130. }
  131. /* Sets the rate limit, 10MBit/s is equal to a rate value of 625, returns previous rate */
  132. int rtl839x_set_egress_rate(struct rtl838x_switch_priv *priv, int port, u32 rate)
  133. {
  134. u32 old_rate;
  135. pr_debug("%s: Setting egress rate on port %d to %d\n", __func__, port, rate);
  136. if (port >= priv->cpu_port)
  137. return -1;
  138. mutex_lock(&priv->reg_mutex);
  139. rtl839x_read_scheduling_table(port);
  140. old_rate = sw_r32(RTL839X_TBL_ACCESS_DATA_2(7)) & 0xff;
  141. old_rate <<= 12;
  142. old_rate |= sw_r32(RTL839X_TBL_ACCESS_DATA_2(8)) >> 20;
  143. sw_w32_mask(0xff, (rate >> 12) & 0xff, RTL839X_TBL_ACCESS_DATA_2(7));
  144. sw_w32_mask(0xfff << 20, rate << 20, RTL839X_TBL_ACCESS_DATA_2(8));
  145. rtl839x_write_scheduling_table(port);
  146. mutex_unlock(&priv->reg_mutex);
  147. return old_rate;
  148. }
  149. /* Set the rate limit for a particular queue in Bits/s
  150. * units of the rate is 16Kbps
  151. */
  152. void rtl839x_egress_rate_queue_limit(struct rtl838x_switch_priv *priv, int port,
  153. int queue, u32 rate)
  154. {
  155. int lsb = 128 + queue * 20;
  156. int low_byte = 8 - (lsb >> 5);
  157. int start_bit = lsb - (low_byte << 5);
  158. u32 high_mask = 0xfffff >> (32 - start_bit);
  159. pr_debug("%s: Setting egress rate on port %d, queue %d to %d\n",
  160. __func__, port, queue, rate);
  161. if (port >= priv->cpu_port)
  162. return;
  163. if (queue > 7)
  164. return;
  165. mutex_lock(&priv->reg_mutex);
  166. rtl839x_read_scheduling_table(port);
  167. sw_w32_mask(0xfffff << start_bit, (rate & 0xfffff) << start_bit,
  168. RTL839X_TBL_ACCESS_DATA_2(low_byte));
  169. if (high_mask)
  170. sw_w32_mask(high_mask, (rate & 0xfffff) >> (32- start_bit),
  171. RTL839X_TBL_ACCESS_DATA_2(low_byte - 1));
  172. rtl839x_write_scheduling_table(port);
  173. mutex_unlock(&priv->reg_mutex);
  174. }
  175. static void rtl839x_rate_control_init(struct rtl838x_switch_priv *priv)
  176. {
  177. int p, q;
  178. pr_info("%s: enabling rate control\n", __func__);
  179. /* Tick length and token size settings for SoC with 250MHz,
  180. * RTL8350 family would use 50MHz
  181. */
  182. // Set the special tick period
  183. sw_w32(976563, RTL839X_STORM_CTRL_SPCL_LB_TICK_TKN_CTRL);
  184. // Ingress tick period and token length 10G
  185. sw_w32(18 << 11 | 151, RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_0);
  186. // Ingress tick period and token length 1G
  187. sw_w32(245 << 11 | 129, RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_1);
  188. // Egress tick period 10G, bytes/token 10G and tick period 1G, bytes/token 1G
  189. sw_w32(18 << 24 | 151 << 16 | 185 << 8 | 97, RTL839X_SCHED_LB_TICK_TKN_CTRL);
  190. // Set the tick period of the CPU and the Token Len
  191. sw_w32(3815 << 8 | 1, RTL839X_SCHED_LB_TICK_TKN_PPS_CTRL);
  192. // Set the Weighted Fair Queueing burst size
  193. sw_w32_mask(0xffff, 4500, RTL839X_SCHED_LB_THR);
  194. // Storm-rate calculation is based on bytes/sec (bit 5), include IFG (bit 6)
  195. sw_w32_mask(0, 1 << 5 | 1 << 6, RTL839X_STORM_CTRL);
  196. /* Based on the rate control mode being bytes/s
  197. * set tick period and token length for 10G
  198. */
  199. sw_w32(18 << 10 | 151, RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_0);
  200. /* and for 1G ports */
  201. sw_w32(246 << 10 | 129, RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_1);
  202. /* Set default burst rates on all ports (the same for 1G / 10G) with a PHY
  203. * for UC, MC and BC
  204. * For 1G port, the minimum burst rate is 1700, maximum 65535,
  205. * For 10G ports it is 2650 and 1048575 respectively */
  206. for (p = 0; p < priv->cpu_port; p++) {
  207. if (priv->ports[p].phy && !priv->ports[p].is10G) {
  208. sw_w32_mask(0xffff, 0x8000, RTL839X_STORM_CTRL_PORT_UC_1(p));
  209. sw_w32_mask(0xffff, 0x8000, RTL839X_STORM_CTRL_PORT_MC_1(p));
  210. sw_w32_mask(0xffff, 0x8000, RTL839X_STORM_CTRL_PORT_BC_1(p));
  211. }
  212. }
  213. /* Setup ingress/egress per-port rate control */
  214. for (p = 0; p < priv->cpu_port; p++) {
  215. if (!priv->ports[p].phy)
  216. continue;
  217. if (priv->ports[p].is10G)
  218. rtl839x_set_egress_rate(priv, p, 625000); // 10GB/s
  219. else
  220. rtl839x_set_egress_rate(priv, p, 62500); // 1GB/s
  221. // Setup queues: all RTL83XX SoCs have 8 queues, maximum rate
  222. for (q = 0; q < 8; q++)
  223. rtl839x_egress_rate_queue_limit(priv, p, q, 0xfffff);
  224. if (priv->ports[p].is10G) {
  225. // Set high threshold to maximum
  226. sw_w32_mask(0xffff, 0xffff, RTL839X_IGR_BWCTRL_PORT_CTRL_10G_0(p));
  227. } else {
  228. // Set high threshold to maximum
  229. sw_w32_mask(0xffff, 0xffff, RTL839X_IGR_BWCTRL_PORT_CTRL_1(p));
  230. }
  231. }
  232. // Set global ingress low watermark rate
  233. sw_w32(65532, RTL839X_IGR_BWCTRL_CTRL_LB_THR);
  234. }
  235. void rtl838x_setup_prio2queue_matrix(int *min_queues)
  236. {
  237. int i;
  238. u32 v;
  239. pr_info("Current Intprio2queue setting: %08x\n", sw_r32(RTL838X_QM_INTPRI2QID_CTRL));
  240. for (i = 0; i < MAX_PRIOS; i++)
  241. v |= i << (min_queues[i] * 3);
  242. sw_w32(v, RTL838X_QM_INTPRI2QID_CTRL);
  243. }
  244. void rtl839x_setup_prio2queue_matrix(int *min_queues)
  245. {
  246. int i, q;
  247. pr_info("Current Intprio2queue setting: %08x\n", sw_r32(RTL839X_QM_INTPRI2QID_CTRL(0)));
  248. for (i = 0; i < MAX_PRIOS; i++) {
  249. q = min_queues[i];
  250. sw_w32(i << (q * 3), RTL839X_QM_INTPRI2QID_CTRL(q));
  251. }
  252. }
  253. /* Sets the CPU queue depending on the internal priority of a packet */
  254. void rtl83xx_setup_prio2queue_cpu_matrix(int *max_queues)
  255. {
  256. int reg = soc_info.family == RTL8380_FAMILY_ID ? RTL838X_QM_PKT2CPU_INTPRI_MAP
  257. : RTL839X_QM_PKT2CPU_INTPRI_MAP;
  258. int i;
  259. u32 v;
  260. pr_info("QM_PKT2CPU_INTPRI_MAP: %08x\n", sw_r32(reg));
  261. for (i = 0; i < MAX_PRIOS; i++)
  262. v |= max_queues[i] << (i * 3);
  263. sw_w32(v, reg);
  264. }
  265. void rtl83xx_setup_default_prio2queue(void)
  266. {
  267. if (soc_info.family == RTL8380_FAMILY_ID) {
  268. rtl838x_setup_prio2queue_matrix(max_available_queue);
  269. } else {
  270. rtl839x_setup_prio2queue_matrix(max_available_queue);
  271. }
  272. rtl83xx_setup_prio2queue_cpu_matrix(max_available_queue);
  273. }
  274. /* Sets the output queue assigned to a port, the port can be the CPU-port */
  275. void rtl839x_set_egress_queue(int port, int queue)
  276. {
  277. sw_w32(queue << ((port % 10) *3), RTL839X_QM_PORT_QNUM(port));
  278. }
  279. /* Sets the priority assigned of an ingress port, the port can be the CPU-port */
  280. void rtl83xx_set_ingress_priority(int port, int priority)
  281. {
  282. if (soc_info.family == RTL8380_FAMILY_ID)
  283. sw_w32(priority << ((port % 10) *3), RTL838X_PRI_SEL_PORT_PRI(port));
  284. else
  285. sw_w32(priority << ((port % 10) *3), RTL839X_PRI_SEL_PORT_PRI(port));
  286. }
  287. int rtl839x_get_scheduling_algorithm(struct rtl838x_switch_priv *priv, int port)
  288. {
  289. u32 v;
  290. mutex_lock(&priv->reg_mutex);
  291. rtl839x_read_scheduling_table(port);
  292. v = sw_r32(RTL839X_TBL_ACCESS_DATA_2(8));
  293. mutex_unlock(&priv->reg_mutex);
  294. if (v & BIT(19))
  295. return WEIGHTED_ROUND_ROBIN;
  296. return WEIGHTED_FAIR_QUEUE;
  297. }
  298. void rtl839x_set_scheduling_algorithm(struct rtl838x_switch_priv *priv, int port,
  299. enum scheduler_type sched)
  300. {
  301. enum scheduler_type t = rtl839x_get_scheduling_algorithm(priv, port);
  302. u32 v, oam_state, oam_port_state;
  303. u32 count;
  304. int i, egress_rate;
  305. mutex_lock(&priv->reg_mutex);
  306. /* Check whether we need to empty the egress queue of that port due to Errata E0014503 */
  307. if (sched == WEIGHTED_FAIR_QUEUE && t == WEIGHTED_ROUND_ROBIN && port != priv->cpu_port) {
  308. // Read Operations, Adminstatrion and Management control register
  309. oam_state = sw_r32(RTL839X_OAM_CTRL);
  310. // Get current OAM state
  311. oam_port_state = sw_r32(RTL839X_OAM_PORT_ACT_CTRL(port));
  312. // Disable OAM to block traffice
  313. v = sw_r32(RTL839X_OAM_CTRL);
  314. sw_w32_mask(0, 1, RTL839X_OAM_CTRL);
  315. v = sw_r32(RTL839X_OAM_CTRL);
  316. // Set to trap action OAM forward (bits 1, 2) and OAM Mux Action Drop (bit 0)
  317. sw_w32(0x2, RTL839X_OAM_PORT_ACT_CTRL(port));
  318. // Set port egress rate to unlimited
  319. egress_rate = rtl839x_set_egress_rate(priv, port, 0xFFFFF);
  320. // Wait until the egress used page count of that port is 0
  321. i = 0;
  322. do {
  323. usleep_range(100, 200);
  324. rtl839x_read_out_q_table(port);
  325. count = sw_r32(RTL839X_TBL_ACCESS_DATA_2(6));
  326. count >>= 20;
  327. i++;
  328. } while (i < 3500 && count > 0);
  329. }
  330. // Actually set the scheduling algorithm
  331. rtl839x_read_scheduling_table(port);
  332. sw_w32_mask(BIT(19), sched ? BIT(19) : 0, RTL839X_TBL_ACCESS_DATA_2(8));
  333. rtl839x_write_scheduling_table(port);
  334. if (sched == WEIGHTED_FAIR_QUEUE && t == WEIGHTED_ROUND_ROBIN && port != priv->cpu_port) {
  335. // Restore OAM state to control register
  336. sw_w32(oam_state, RTL839X_OAM_CTRL);
  337. // Restore trap action state
  338. sw_w32(oam_port_state, RTL839X_OAM_PORT_ACT_CTRL(port));
  339. // Restore port egress rate
  340. rtl839x_set_egress_rate(priv, port, egress_rate);
  341. }
  342. mutex_unlock(&priv->reg_mutex);
  343. }
  344. void rtl839x_set_scheduling_queue_weights(struct rtl838x_switch_priv *priv, int port,
  345. int *queue_weights)
  346. {
  347. int i, lsb, low_byte, start_bit, high_mask;
  348. mutex_lock(&priv->reg_mutex);
  349. rtl839x_read_scheduling_table(port);
  350. for (i = 0; i < 8; i++) {
  351. lsb = 48 + i * 8;
  352. low_byte = 8 - (lsb >> 5);
  353. start_bit = lsb - (low_byte << 5);
  354. high_mask = 0x3ff >> (32 - start_bit);
  355. sw_w32_mask(0x3ff << start_bit, (queue_weights[i] & 0x3ff) << start_bit,
  356. RTL839X_TBL_ACCESS_DATA_2(low_byte));
  357. if (high_mask)
  358. sw_w32_mask(high_mask, (queue_weights[i] & 0x3ff) >> (32- start_bit),
  359. RTL839X_TBL_ACCESS_DATA_2(low_byte - 1));
  360. }
  361. rtl839x_write_scheduling_table(port);
  362. mutex_unlock(&priv->reg_mutex);
  363. }
  364. void rtl838x_config_qos(void)
  365. {
  366. int i, p;
  367. u32 v;
  368. pr_info("Setting up RTL838X QoS\n");
  369. pr_info("RTL838X_PRI_SEL_TBL_CTRL(i): %08x\n", sw_r32(RTL838X_PRI_SEL_TBL_CTRL(0)));
  370. rtl83xx_setup_default_prio2queue();
  371. // Enable inner (bit 12) and outer (bit 13) priority remapping from DSCP
  372. sw_w32_mask(0, BIT(12) | BIT(13), RTL838X_PRI_DSCP_INVLD_CTRL0);
  373. /* Set default weight for calculating internal priority, in prio selection group 0
  374. * Port based (prio 3), Port outer-tag (4), DSCP (5), Inner Tag (6), Outer Tag (7)
  375. */
  376. v = 3 | (4 << 3) | (5 << 6) | (6 << 9) | (7 << 12);
  377. sw_w32(v, RTL838X_PRI_SEL_TBL_CTRL(0));
  378. // Set the inner and outer priority one-to-one to re-marked outer dot1p priority
  379. v = 0;
  380. for (p = 0; p < 8; p++)
  381. v |= p << (3 * p);
  382. sw_w32(v, RTL838X_RMK_OPRI_CTRL);
  383. sw_w32(v, RTL838X_RMK_IPRI_CTRL);
  384. v = 0;
  385. for (p = 0; p < 8; p++)
  386. v |= (dot1p_priority_remapping[p] & 0x7) << (p * 3);
  387. sw_w32(v, RTL838X_PRI_SEL_IPRI_REMAP);
  388. // On all ports set scheduler type to WFQ
  389. for (i = 0; i <= soc_info.cpu_port; i++)
  390. sw_w32(0, RTL838X_SCHED_P_TYPE_CTRL(i));
  391. // Enable egress scheduler for CPU-Port
  392. sw_w32_mask(0, BIT(8), RTL838X_SCHED_LB_CTRL(soc_info.cpu_port));
  393. // Enable egress drop allways on
  394. sw_w32_mask(0, BIT(11), RTL838X_FC_P_EGR_DROP_CTRL(soc_info.cpu_port));
  395. // Give special trap frames priority 7 (BPDUs) and routing exceptions:
  396. sw_w32_mask(0, 7 << 3 | 7, RTL838X_QM_PKT2CPU_INTPRI_2);
  397. // Give RMA frames priority 7:
  398. sw_w32_mask(0, 7, RTL838X_QM_PKT2CPU_INTPRI_1);
  399. }
  400. void rtl839x_config_qos(void)
  401. {
  402. int port, p, q;
  403. u32 v;
  404. struct rtl838x_switch_priv *priv = switch_priv;
  405. pr_info("Setting up RTL839X QoS\n");
  406. pr_info("RTL839X_PRI_SEL_TBL_CTRL(i): %08x\n", sw_r32(RTL839X_PRI_SEL_TBL_CTRL(0)));
  407. rtl83xx_setup_default_prio2queue();
  408. for (port = 0; port < soc_info.cpu_port; port++)
  409. sw_w32(7, RTL839X_QM_PORT_QNUM(port));
  410. // CPU-port gets queue number 7
  411. sw_w32(7, RTL839X_QM_PORT_QNUM(soc_info.cpu_port));
  412. for (port = 0; port <= soc_info.cpu_port; port++) {
  413. rtl83xx_set_ingress_priority(port, 0);
  414. rtl839x_set_scheduling_algorithm(priv, port, WEIGHTED_FAIR_QUEUE);
  415. rtl839x_set_scheduling_queue_weights(priv, port, default_queue_weights);
  416. // Do re-marking based on outer tag
  417. sw_w32_mask(0, BIT(port % 32), RTL839X_RMK_PORT_DEI_TAG_CTRL(port));
  418. }
  419. // Remap dot1p priorities to internal priority, for this the outer tag needs be re-marked
  420. v = 0;
  421. for (p = 0; p < 8; p++)
  422. v |= (dot1p_priority_remapping[p] & 0x7) << (p * 3);
  423. sw_w32(v, RTL839X_PRI_SEL_IPRI_REMAP);
  424. /* Configure Drop Precedence for Drop Eligible Indicator (DEI)
  425. * Index 0: 0
  426. * Index 1: 2
  427. * Each indicator is 2 bits long
  428. */
  429. sw_w32(2 << 2, RTL839X_PRI_SEL_DEI2DP_REMAP);
  430. // Re-mark DEI: 4 bit-fields of 2 bits each, field 0 is bits 0-1, ...
  431. sw_w32((0x1 << 2) | (0x1 << 4), RTL839X_RMK_DEI_CTRL);
  432. /* Set Congestion avoidance drop probability to 0 for drop precedences 0-2 (bits 24-31)
  433. * low threshold (bits 0-11) to 4095 and high threshold (bits 12-23) to 4095
  434. * Weighted Random Early Detection (WRED) is used
  435. */
  436. sw_w32(4095 << 12| 4095, RTL839X_WRED_PORT_THR_CTRL(0));
  437. sw_w32(4095 << 12| 4095, RTL839X_WRED_PORT_THR_CTRL(1));
  438. sw_w32(4095 << 12| 4095, RTL839X_WRED_PORT_THR_CTRL(2));
  439. /* Set queue-based congestion avoidance properties, register fields are as
  440. * for forward RTL839X_WRED_PORT_THR_CTRL
  441. */
  442. for (q = 0; q < 8; q++) {
  443. sw_w32(255 << 24 | 78 << 12 | 68, RTL839X_WRED_QUEUE_THR_CTRL(q, 0));
  444. sw_w32(255 << 24 | 74 << 12 | 64, RTL839X_WRED_QUEUE_THR_CTRL(q, 0));
  445. sw_w32(255 << 24 | 70 << 12 | 60, RTL839X_WRED_QUEUE_THR_CTRL(q, 0));
  446. }
  447. }
  448. void __init rtl83xx_setup_qos(struct rtl838x_switch_priv *priv)
  449. {
  450. switch_priv = priv;
  451. pr_info("In %s\n", __func__);
  452. if (priv->family_id == RTL8380_FAMILY_ID)
  453. return rtl838x_config_qos();
  454. else if (priv->family_id == RTL8390_FAMILY_ID)
  455. return rtl839x_config_qos();
  456. if (priv->family_id == RTL8380_FAMILY_ID)
  457. rtl838x_rate_control_init(priv);
  458. else if (priv->family_id == RTL8390_FAMILY_ID)
  459. rtl839x_rate_control_init(priv);
  460. }