PageRenderTime 79ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/bna/bna_txrx.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 4185 lines | 3204 code | 696 blank | 285 comment | 312 complexity | c8af6c0c5ef9c147e562447b9d878faa MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include "bna.h"
  19. #include "bfa_sm.h"
  20. #include "bfi.h"
  21. /**
  22. * IB
  23. */
  24. #define bna_ib_find_free_ibidx(_mask, _pos)\
  25. do {\
  26. (_pos) = 0;\
  27. while (((_pos) < (BFI_IBIDX_MAX_SEGSIZE)) &&\
  28. ((1 << (_pos)) & (_mask)))\
  29. (_pos)++;\
  30. } while (0)
  31. #define bna_ib_count_ibidx(_mask, _count)\
  32. do {\
  33. int pos = 0;\
  34. (_count) = 0;\
  35. while (pos < (BFI_IBIDX_MAX_SEGSIZE)) {\
  36. if ((1 << pos) & (_mask))\
  37. (_count) = pos + 1;\
  38. pos++;\
  39. } \
  40. } while (0)
  41. #define bna_ib_select_segpool(_count, _q_idx)\
  42. do {\
  43. int i;\
  44. (_q_idx) = -1;\
  45. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {\
  46. if ((_count <= ibidx_pool[i].pool_entry_size)) {\
  47. (_q_idx) = i;\
  48. break;\
  49. } \
  50. } \
  51. } while (0)
  52. struct bna_ibidx_pool {
  53. int pool_size;
  54. int pool_entry_size;
  55. };
  56. init_ibidx_pool(ibidx_pool);
  57. static struct bna_intr *
  58. bna_intr_get(struct bna_ib_mod *ib_mod, enum bna_intr_type intr_type,
  59. int vector)
  60. {
  61. struct bna_intr *intr;
  62. struct list_head *qe;
  63. list_for_each(qe, &ib_mod->intr_active_q) {
  64. intr = (struct bna_intr *)qe;
  65. if ((intr->intr_type == intr_type) &&
  66. (intr->vector == vector)) {
  67. intr->ref_count++;
  68. return intr;
  69. }
  70. }
  71. if (list_empty(&ib_mod->intr_free_q))
  72. return NULL;
  73. bfa_q_deq(&ib_mod->intr_free_q, &intr);
  74. bfa_q_qe_init(&intr->qe);
  75. intr->ref_count = 1;
  76. intr->intr_type = intr_type;
  77. intr->vector = vector;
  78. list_add_tail(&intr->qe, &ib_mod->intr_active_q);
  79. return intr;
  80. }
  81. static void
  82. bna_intr_put(struct bna_ib_mod *ib_mod,
  83. struct bna_intr *intr)
  84. {
  85. intr->ref_count--;
  86. if (intr->ref_count == 0) {
  87. intr->ib = NULL;
  88. list_del(&intr->qe);
  89. bfa_q_qe_init(&intr->qe);
  90. list_add_tail(&intr->qe, &ib_mod->intr_free_q);
  91. }
  92. }
  93. void
  94. bna_ib_mod_init(struct bna_ib_mod *ib_mod, struct bna *bna,
  95. struct bna_res_info *res_info)
  96. {
  97. int i;
  98. int j;
  99. int count;
  100. u8 offset;
  101. struct bna_doorbell_qset *qset;
  102. unsigned long off;
  103. ib_mod->bna = bna;
  104. ib_mod->ib = (struct bna_ib *)
  105. res_info[BNA_RES_MEM_T_IB_ARRAY].res_u.mem_info.mdl[0].kva;
  106. ib_mod->intr = (struct bna_intr *)
  107. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_u.mem_info.mdl[0].kva;
  108. ib_mod->idx_seg = (struct bna_ibidx_seg *)
  109. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_u.mem_info.mdl[0].kva;
  110. INIT_LIST_HEAD(&ib_mod->ib_free_q);
  111. INIT_LIST_HEAD(&ib_mod->intr_free_q);
  112. INIT_LIST_HEAD(&ib_mod->intr_active_q);
  113. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++)
  114. INIT_LIST_HEAD(&ib_mod->ibidx_seg_pool[i]);
  115. for (i = 0; i < BFI_MAX_IB; i++) {
  116. ib_mod->ib[i].ib_id = i;
  117. ib_mod->ib[i].ib_seg_host_addr_kva =
  118. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].kva;
  119. ib_mod->ib[i].ib_seg_host_addr.lsb =
  120. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].dma.lsb;
  121. ib_mod->ib[i].ib_seg_host_addr.msb =
  122. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].dma.msb;
  123. qset = (struct bna_doorbell_qset *)0;
  124. off = (unsigned long)(&qset[i >> 1].ib0[(i & 0x1)
  125. * (0x20 >> 2)]);
  126. ib_mod->ib[i].door_bell.doorbell_addr = off +
  127. BNA_GET_DOORBELL_BASE_ADDR(bna->pcidev.pci_bar_kva);
  128. bfa_q_qe_init(&ib_mod->ib[i].qe);
  129. list_add_tail(&ib_mod->ib[i].qe, &ib_mod->ib_free_q);
  130. bfa_q_qe_init(&ib_mod->intr[i].qe);
  131. list_add_tail(&ib_mod->intr[i].qe, &ib_mod->intr_free_q);
  132. }
  133. count = 0;
  134. offset = 0;
  135. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {
  136. for (j = 0; j < ibidx_pool[i].pool_size; j++) {
  137. bfa_q_qe_init(&ib_mod->idx_seg[count]);
  138. ib_mod->idx_seg[count].ib_seg_size =
  139. ibidx_pool[i].pool_entry_size;
  140. ib_mod->idx_seg[count].ib_idx_tbl_offset = offset;
  141. list_add_tail(&ib_mod->idx_seg[count].qe,
  142. &ib_mod->ibidx_seg_pool[i]);
  143. count++;
  144. offset += ibidx_pool[i].pool_entry_size;
  145. }
  146. }
  147. }
  148. void
  149. bna_ib_mod_uninit(struct bna_ib_mod *ib_mod)
  150. {
  151. int i;
  152. int j;
  153. struct list_head *qe;
  154. i = 0;
  155. list_for_each(qe, &ib_mod->ib_free_q)
  156. i++;
  157. i = 0;
  158. list_for_each(qe, &ib_mod->intr_free_q)
  159. i++;
  160. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {
  161. j = 0;
  162. list_for_each(qe, &ib_mod->ibidx_seg_pool[i])
  163. j++;
  164. }
  165. ib_mod->bna = NULL;
  166. }
  167. static struct bna_ib *
  168. bna_ib_get(struct bna_ib_mod *ib_mod,
  169. enum bna_intr_type intr_type,
  170. int vector)
  171. {
  172. struct bna_ib *ib;
  173. struct bna_intr *intr;
  174. if (intr_type == BNA_INTR_T_INTX)
  175. vector = (1 << vector);
  176. intr = bna_intr_get(ib_mod, intr_type, vector);
  177. if (intr == NULL)
  178. return NULL;
  179. if (intr->ib) {
  180. if (intr->ib->ref_count == BFI_IBIDX_MAX_SEGSIZE) {
  181. bna_intr_put(ib_mod, intr);
  182. return NULL;
  183. }
  184. intr->ib->ref_count++;
  185. return intr->ib;
  186. }
  187. if (list_empty(&ib_mod->ib_free_q)) {
  188. bna_intr_put(ib_mod, intr);
  189. return NULL;
  190. }
  191. bfa_q_deq(&ib_mod->ib_free_q, &ib);
  192. bfa_q_qe_init(&ib->qe);
  193. ib->ref_count = 1;
  194. ib->start_count = 0;
  195. ib->idx_mask = 0;
  196. ib->intr = intr;
  197. ib->idx_seg = NULL;
  198. intr->ib = ib;
  199. ib->bna = ib_mod->bna;
  200. return ib;
  201. }
  202. static void
  203. bna_ib_put(struct bna_ib_mod *ib_mod, struct bna_ib *ib)
  204. {
  205. bna_intr_put(ib_mod, ib->intr);
  206. ib->ref_count--;
  207. if (ib->ref_count == 0) {
  208. ib->intr = NULL;
  209. ib->bna = NULL;
  210. list_add_tail(&ib->qe, &ib_mod->ib_free_q);
  211. }
  212. }
  213. /* Returns index offset - starting from 0 */
  214. static int
  215. bna_ib_reserve_idx(struct bna_ib *ib)
  216. {
  217. struct bna_ib_mod *ib_mod = &ib->bna->ib_mod;
  218. struct bna_ibidx_seg *idx_seg;
  219. int idx;
  220. int num_idx;
  221. int q_idx;
  222. /* Find the first free index position */
  223. bna_ib_find_free_ibidx(ib->idx_mask, idx);
  224. if (idx == BFI_IBIDX_MAX_SEGSIZE)
  225. return -1;
  226. /*
  227. * Calculate the total number of indexes held by this IB,
  228. * including the index newly reserved above.
  229. */
  230. bna_ib_count_ibidx((ib->idx_mask | (1 << idx)), num_idx);
  231. /* See if there is a free space in the index segment held by this IB */
  232. if (ib->idx_seg && (num_idx <= ib->idx_seg->ib_seg_size)) {
  233. ib->idx_mask |= (1 << idx);
  234. return idx;
  235. }
  236. if (ib->start_count)
  237. return -1;
  238. /* Allocate a new segment */
  239. bna_ib_select_segpool(num_idx, q_idx);
  240. while (1) {
  241. if (q_idx == BFI_IBIDX_TOTAL_POOLS)
  242. return -1;
  243. if (!list_empty(&ib_mod->ibidx_seg_pool[q_idx]))
  244. break;
  245. q_idx++;
  246. }
  247. bfa_q_deq(&ib_mod->ibidx_seg_pool[q_idx], &idx_seg);
  248. bfa_q_qe_init(&idx_seg->qe);
  249. /* Free the old segment */
  250. if (ib->idx_seg) {
  251. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, q_idx);
  252. list_add_tail(&ib->idx_seg->qe, &ib_mod->ibidx_seg_pool[q_idx]);
  253. }
  254. ib->idx_seg = idx_seg;
  255. ib->idx_mask |= (1 << idx);
  256. return idx;
  257. }
  258. static void
  259. bna_ib_release_idx(struct bna_ib *ib, int idx)
  260. {
  261. struct bna_ib_mod *ib_mod = &ib->bna->ib_mod;
  262. struct bna_ibidx_seg *idx_seg;
  263. int num_idx;
  264. int cur_q_idx;
  265. int new_q_idx;
  266. ib->idx_mask &= ~(1 << idx);
  267. if (ib->start_count)
  268. return;
  269. bna_ib_count_ibidx(ib->idx_mask, num_idx);
  270. /*
  271. * Free the segment, if there are no more indexes in the segment
  272. * held by this IB
  273. */
  274. if (!num_idx) {
  275. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, cur_q_idx);
  276. list_add_tail(&ib->idx_seg->qe,
  277. &ib_mod->ibidx_seg_pool[cur_q_idx]);
  278. ib->idx_seg = NULL;
  279. return;
  280. }
  281. /* See if we can move to a smaller segment */
  282. bna_ib_select_segpool(num_idx, new_q_idx);
  283. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, cur_q_idx);
  284. while (new_q_idx < cur_q_idx) {
  285. if (!list_empty(&ib_mod->ibidx_seg_pool[new_q_idx]))
  286. break;
  287. new_q_idx++;
  288. }
  289. if (new_q_idx < cur_q_idx) {
  290. /* Select the new smaller segment */
  291. bfa_q_deq(&ib_mod->ibidx_seg_pool[new_q_idx], &idx_seg);
  292. bfa_q_qe_init(&idx_seg->qe);
  293. /* Free the old segment */
  294. list_add_tail(&ib->idx_seg->qe,
  295. &ib_mod->ibidx_seg_pool[cur_q_idx]);
  296. ib->idx_seg = idx_seg;
  297. }
  298. }
  299. static int
  300. bna_ib_config(struct bna_ib *ib, struct bna_ib_config *ib_config)
  301. {
  302. if (ib->start_count)
  303. return -1;
  304. ib->ib_config.coalescing_timeo = ib_config->coalescing_timeo;
  305. ib->ib_config.interpkt_timeo = ib_config->interpkt_timeo;
  306. ib->ib_config.interpkt_count = ib_config->interpkt_count;
  307. ib->ib_config.ctrl_flags = ib_config->ctrl_flags;
  308. ib->ib_config.ctrl_flags |= BFI_IB_CF_MASTER_ENABLE;
  309. if (ib->intr->intr_type == BNA_INTR_T_MSIX)
  310. ib->ib_config.ctrl_flags |= BFI_IB_CF_MSIX_MODE;
  311. return 0;
  312. }
  313. static void
  314. bna_ib_start(struct bna_ib *ib)
  315. {
  316. struct bna_ib_blk_mem ib_cfg;
  317. struct bna_ib_blk_mem *ib_mem;
  318. u32 pg_num;
  319. u32 intx_mask;
  320. int i;
  321. void __iomem *base_addr;
  322. unsigned long off;
  323. ib->start_count++;
  324. if (ib->start_count > 1)
  325. return;
  326. ib_cfg.host_addr_lo = (u32)(ib->ib_seg_host_addr.lsb);
  327. ib_cfg.host_addr_hi = (u32)(ib->ib_seg_host_addr.msb);
  328. ib_cfg.clsc_n_ctrl_n_msix = (((u32)
  329. ib->ib_config.coalescing_timeo << 16) |
  330. ((u32)ib->ib_config.ctrl_flags << 8) |
  331. (ib->intr->vector));
  332. ib_cfg.ipkt_n_ent_n_idxof =
  333. ((u32)
  334. (ib->ib_config.interpkt_timeo & 0xf) << 16) |
  335. ((u32)ib->idx_seg->ib_seg_size << 8) |
  336. (ib->idx_seg->ib_idx_tbl_offset);
  337. ib_cfg.ipkt_cnt_cfg_n_unacked = ((u32)
  338. ib->ib_config.interpkt_count << 24);
  339. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + ib->bna->port_num,
  340. HQM_IB_RAM_BASE_OFFSET);
  341. writel(pg_num, ib->bna->regs.page_addr);
  342. base_addr = BNA_GET_MEM_BASE_ADDR(ib->bna->pcidev.pci_bar_kva,
  343. HQM_IB_RAM_BASE_OFFSET);
  344. ib_mem = (struct bna_ib_blk_mem *)0;
  345. off = (unsigned long)&ib_mem[ib->ib_id].host_addr_lo;
  346. writel(htonl(ib_cfg.host_addr_lo), base_addr + off);
  347. off = (unsigned long)&ib_mem[ib->ib_id].host_addr_hi;
  348. writel(htonl(ib_cfg.host_addr_hi), base_addr + off);
  349. off = (unsigned long)&ib_mem[ib->ib_id].clsc_n_ctrl_n_msix;
  350. writel(ib_cfg.clsc_n_ctrl_n_msix, base_addr + off);
  351. off = (unsigned long)&ib_mem[ib->ib_id].ipkt_n_ent_n_idxof;
  352. writel(ib_cfg.ipkt_n_ent_n_idxof, base_addr + off);
  353. off = (unsigned long)&ib_mem[ib->ib_id].ipkt_cnt_cfg_n_unacked;
  354. writel(ib_cfg.ipkt_cnt_cfg_n_unacked, base_addr + off);
  355. ib->door_bell.doorbell_ack = BNA_DOORBELL_IB_INT_ACK(
  356. (u32)ib->ib_config.coalescing_timeo, 0);
  357. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + ib->bna->port_num,
  358. HQM_INDX_TBL_RAM_BASE_OFFSET);
  359. writel(pg_num, ib->bna->regs.page_addr);
  360. base_addr = BNA_GET_MEM_BASE_ADDR(ib->bna->pcidev.pci_bar_kva,
  361. HQM_INDX_TBL_RAM_BASE_OFFSET);
  362. for (i = 0; i < ib->idx_seg->ib_seg_size; i++) {
  363. off = (unsigned long)
  364. ((ib->idx_seg->ib_idx_tbl_offset + i) * BFI_IBIDX_SIZE);
  365. writel(0, base_addr + off);
  366. }
  367. if (ib->intr->intr_type == BNA_INTR_T_INTX) {
  368. bna_intx_disable(ib->bna, intx_mask);
  369. intx_mask &= ~(ib->intr->vector);
  370. bna_intx_enable(ib->bna, intx_mask);
  371. }
  372. }
  373. static void
  374. bna_ib_stop(struct bna_ib *ib)
  375. {
  376. u32 intx_mask;
  377. ib->start_count--;
  378. if (ib->start_count == 0) {
  379. writel(BNA_DOORBELL_IB_INT_DISABLE,
  380. ib->door_bell.doorbell_addr);
  381. if (ib->intr->intr_type == BNA_INTR_T_INTX) {
  382. bna_intx_disable(ib->bna, intx_mask);
  383. intx_mask |= (ib->intr->vector);
  384. bna_intx_enable(ib->bna, intx_mask);
  385. }
  386. }
  387. }
  388. static void
  389. bna_ib_fail(struct bna_ib *ib)
  390. {
  391. ib->start_count = 0;
  392. }
  393. /**
  394. * RXF
  395. */
  396. static void rxf_enable(struct bna_rxf *rxf);
  397. static void rxf_disable(struct bna_rxf *rxf);
  398. static void __rxf_config_set(struct bna_rxf *rxf);
  399. static void __rxf_rit_set(struct bna_rxf *rxf);
  400. static void __bna_rxf_stat_clr(struct bna_rxf *rxf);
  401. static int rxf_process_packet_filter(struct bna_rxf *rxf);
  402. static int rxf_clear_packet_filter(struct bna_rxf *rxf);
  403. static void rxf_reset_packet_filter(struct bna_rxf *rxf);
  404. static void rxf_cb_enabled(void *arg, int status);
  405. static void rxf_cb_disabled(void *arg, int status);
  406. static void bna_rxf_cb_stats_cleared(void *arg, int status);
  407. static void __rxf_enable(struct bna_rxf *rxf);
  408. static void __rxf_disable(struct bna_rxf *rxf);
  409. bfa_fsm_state_decl(bna_rxf, stopped, struct bna_rxf,
  410. enum bna_rxf_event);
  411. bfa_fsm_state_decl(bna_rxf, start_wait, struct bna_rxf,
  412. enum bna_rxf_event);
  413. bfa_fsm_state_decl(bna_rxf, cam_fltr_mod_wait, struct bna_rxf,
  414. enum bna_rxf_event);
  415. bfa_fsm_state_decl(bna_rxf, started, struct bna_rxf,
  416. enum bna_rxf_event);
  417. bfa_fsm_state_decl(bna_rxf, cam_fltr_clr_wait, struct bna_rxf,
  418. enum bna_rxf_event);
  419. bfa_fsm_state_decl(bna_rxf, stop_wait, struct bna_rxf,
  420. enum bna_rxf_event);
  421. bfa_fsm_state_decl(bna_rxf, pause_wait, struct bna_rxf,
  422. enum bna_rxf_event);
  423. bfa_fsm_state_decl(bna_rxf, resume_wait, struct bna_rxf,
  424. enum bna_rxf_event);
  425. bfa_fsm_state_decl(bna_rxf, stat_clr_wait, struct bna_rxf,
  426. enum bna_rxf_event);
  427. static struct bfa_sm_table rxf_sm_table[] = {
  428. {BFA_SM(bna_rxf_sm_stopped), BNA_RXF_STOPPED},
  429. {BFA_SM(bna_rxf_sm_start_wait), BNA_RXF_START_WAIT},
  430. {BFA_SM(bna_rxf_sm_cam_fltr_mod_wait), BNA_RXF_CAM_FLTR_MOD_WAIT},
  431. {BFA_SM(bna_rxf_sm_started), BNA_RXF_STARTED},
  432. {BFA_SM(bna_rxf_sm_cam_fltr_clr_wait), BNA_RXF_CAM_FLTR_CLR_WAIT},
  433. {BFA_SM(bna_rxf_sm_stop_wait), BNA_RXF_STOP_WAIT},
  434. {BFA_SM(bna_rxf_sm_pause_wait), BNA_RXF_PAUSE_WAIT},
  435. {BFA_SM(bna_rxf_sm_resume_wait), BNA_RXF_RESUME_WAIT},
  436. {BFA_SM(bna_rxf_sm_stat_clr_wait), BNA_RXF_STAT_CLR_WAIT}
  437. };
  438. static void
  439. bna_rxf_sm_stopped_entry(struct bna_rxf *rxf)
  440. {
  441. call_rxf_stop_cbfn(rxf, BNA_CB_SUCCESS);
  442. }
  443. static void
  444. bna_rxf_sm_stopped(struct bna_rxf *rxf, enum bna_rxf_event event)
  445. {
  446. switch (event) {
  447. case RXF_E_START:
  448. bfa_fsm_set_state(rxf, bna_rxf_sm_start_wait);
  449. break;
  450. case RXF_E_STOP:
  451. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  452. break;
  453. case RXF_E_FAIL:
  454. /* No-op */
  455. break;
  456. case RXF_E_CAM_FLTR_MOD:
  457. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  458. break;
  459. case RXF_E_STARTED:
  460. case RXF_E_STOPPED:
  461. case RXF_E_CAM_FLTR_RESP:
  462. /**
  463. * These events are received due to flushing of mbox
  464. * when device fails
  465. */
  466. /* No-op */
  467. break;
  468. case RXF_E_PAUSE:
  469. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  470. call_rxf_pause_cbfn(rxf, BNA_CB_SUCCESS);
  471. break;
  472. case RXF_E_RESUME:
  473. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  474. call_rxf_resume_cbfn(rxf, BNA_CB_SUCCESS);
  475. break;
  476. default:
  477. bfa_sm_fault(rxf->rx->bna, event);
  478. }
  479. }
  480. static void
  481. bna_rxf_sm_start_wait_entry(struct bna_rxf *rxf)
  482. {
  483. __rxf_config_set(rxf);
  484. __rxf_rit_set(rxf);
  485. rxf_enable(rxf);
  486. }
  487. static void
  488. bna_rxf_sm_start_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  489. {
  490. switch (event) {
  491. case RXF_E_STOP:
  492. /**
  493. * STOP is originated from bnad. When this happens,
  494. * it can not be waiting for filter update
  495. */
  496. call_rxf_start_cbfn(rxf, BNA_CB_INTERRUPT);
  497. bfa_fsm_set_state(rxf, bna_rxf_sm_stop_wait);
  498. break;
  499. case RXF_E_FAIL:
  500. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  501. call_rxf_start_cbfn(rxf, BNA_CB_FAIL);
  502. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  503. break;
  504. case RXF_E_CAM_FLTR_MOD:
  505. /* No-op */
  506. break;
  507. case RXF_E_STARTED:
  508. /**
  509. * Force rxf_process_filter() to go through initial
  510. * config
  511. */
  512. if ((rxf->ucast_active_mac != NULL) &&
  513. (rxf->ucast_pending_set == 0))
  514. rxf->ucast_pending_set = 1;
  515. if (rxf->rss_status == BNA_STATUS_T_ENABLED)
  516. rxf->rxf_flags |= BNA_RXF_FL_RSS_CONFIG_PENDING;
  517. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  518. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_mod_wait);
  519. break;
  520. case RXF_E_PAUSE:
  521. case RXF_E_RESUME:
  522. rxf->rxf_flags |= BNA_RXF_FL_OPERSTATE_CHANGED;
  523. break;
  524. default:
  525. bfa_sm_fault(rxf->rx->bna, event);
  526. }
  527. }
  528. static void
  529. bna_rxf_sm_cam_fltr_mod_wait_entry(struct bna_rxf *rxf)
  530. {
  531. if (!rxf_process_packet_filter(rxf)) {
  532. /* No more pending CAM entries to update */
  533. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  534. }
  535. }
  536. static void
  537. bna_rxf_sm_cam_fltr_mod_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  538. {
  539. switch (event) {
  540. case RXF_E_STOP:
  541. /**
  542. * STOP is originated from bnad. When this happens,
  543. * it can not be waiting for filter update
  544. */
  545. call_rxf_start_cbfn(rxf, BNA_CB_INTERRUPT);
  546. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_clr_wait);
  547. break;
  548. case RXF_E_FAIL:
  549. rxf_reset_packet_filter(rxf);
  550. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  551. call_rxf_start_cbfn(rxf, BNA_CB_FAIL);
  552. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  553. break;
  554. case RXF_E_CAM_FLTR_MOD:
  555. /* No-op */
  556. break;
  557. case RXF_E_CAM_FLTR_RESP:
  558. if (!rxf_process_packet_filter(rxf)) {
  559. /* No more pending CAM entries to update */
  560. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  561. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  562. }
  563. break;
  564. case RXF_E_PAUSE:
  565. case RXF_E_RESUME:
  566. rxf->rxf_flags |= BNA_RXF_FL_OPERSTATE_CHANGED;
  567. break;
  568. default:
  569. bfa_sm_fault(rxf->rx->bna, event);
  570. }
  571. }
  572. static void
  573. bna_rxf_sm_started_entry(struct bna_rxf *rxf)
  574. {
  575. call_rxf_start_cbfn(rxf, BNA_CB_SUCCESS);
  576. if (rxf->rxf_flags & BNA_RXF_FL_OPERSTATE_CHANGED) {
  577. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  578. bfa_fsm_send_event(rxf, RXF_E_PAUSE);
  579. else
  580. bfa_fsm_send_event(rxf, RXF_E_RESUME);
  581. }
  582. }
  583. static void
  584. bna_rxf_sm_started(struct bna_rxf *rxf, enum bna_rxf_event event)
  585. {
  586. switch (event) {
  587. case RXF_E_STOP:
  588. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_clr_wait);
  589. /* Hack to get FSM start clearing CAM entries */
  590. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_RESP);
  591. break;
  592. case RXF_E_FAIL:
  593. rxf_reset_packet_filter(rxf);
  594. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  595. break;
  596. case RXF_E_CAM_FLTR_MOD:
  597. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_mod_wait);
  598. break;
  599. case RXF_E_PAUSE:
  600. bfa_fsm_set_state(rxf, bna_rxf_sm_pause_wait);
  601. break;
  602. case RXF_E_RESUME:
  603. bfa_fsm_set_state(rxf, bna_rxf_sm_resume_wait);
  604. break;
  605. default:
  606. bfa_sm_fault(rxf->rx->bna, event);
  607. }
  608. }
  609. static void
  610. bna_rxf_sm_cam_fltr_clr_wait_entry(struct bna_rxf *rxf)
  611. {
  612. /**
  613. * Note: Do not add rxf_clear_packet_filter here.
  614. * It will overstep mbox when this transition happens:
  615. * cam_fltr_mod_wait -> cam_fltr_clr_wait on RXF_E_STOP event
  616. */
  617. }
  618. static void
  619. bna_rxf_sm_cam_fltr_clr_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  620. {
  621. switch (event) {
  622. case RXF_E_FAIL:
  623. /**
  624. * FSM was in the process of stopping, initiated by
  625. * bnad. When this happens, no one can be waiting for
  626. * start or filter update
  627. */
  628. rxf_reset_packet_filter(rxf);
  629. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  630. break;
  631. case RXF_E_CAM_FLTR_RESP:
  632. if (!rxf_clear_packet_filter(rxf)) {
  633. /* No more pending CAM entries to clear */
  634. bfa_fsm_set_state(rxf, bna_rxf_sm_stop_wait);
  635. rxf_disable(rxf);
  636. }
  637. break;
  638. default:
  639. bfa_sm_fault(rxf->rx->bna, event);
  640. }
  641. }
  642. static void
  643. bna_rxf_sm_stop_wait_entry(struct bna_rxf *rxf)
  644. {
  645. /**
  646. * NOTE: Do not add rxf_disable here.
  647. * It will overstep mbox when this transition happens:
  648. * start_wait -> stop_wait on RXF_E_STOP event
  649. */
  650. }
  651. static void
  652. bna_rxf_sm_stop_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  653. {
  654. switch (event) {
  655. case RXF_E_FAIL:
  656. /**
  657. * FSM was in the process of stopping, initiated by
  658. * bnad. When this happens, no one can be waiting for
  659. * start or filter update
  660. */
  661. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  662. break;
  663. case RXF_E_STARTED:
  664. /**
  665. * This event is received due to abrupt transition from
  666. * bna_rxf_sm_start_wait state on receiving
  667. * RXF_E_STOP event
  668. */
  669. rxf_disable(rxf);
  670. break;
  671. case RXF_E_STOPPED:
  672. /**
  673. * FSM was in the process of stopping, initiated by
  674. * bnad. When this happens, no one can be waiting for
  675. * start or filter update
  676. */
  677. bfa_fsm_set_state(rxf, bna_rxf_sm_stat_clr_wait);
  678. break;
  679. case RXF_E_PAUSE:
  680. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  681. break;
  682. case RXF_E_RESUME:
  683. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  684. break;
  685. default:
  686. bfa_sm_fault(rxf->rx->bna, event);
  687. }
  688. }
  689. static void
  690. bna_rxf_sm_pause_wait_entry(struct bna_rxf *rxf)
  691. {
  692. rxf->rxf_flags &=
  693. ~(BNA_RXF_FL_OPERSTATE_CHANGED | BNA_RXF_FL_RXF_ENABLED);
  694. __rxf_disable(rxf);
  695. }
  696. static void
  697. bna_rxf_sm_pause_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  698. {
  699. switch (event) {
  700. case RXF_E_FAIL:
  701. /**
  702. * FSM was in the process of disabling rxf, initiated by
  703. * bnad.
  704. */
  705. call_rxf_pause_cbfn(rxf, BNA_CB_FAIL);
  706. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  707. break;
  708. case RXF_E_STOPPED:
  709. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  710. call_rxf_pause_cbfn(rxf, BNA_CB_SUCCESS);
  711. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  712. break;
  713. /*
  714. * Since PAUSE/RESUME can only be sent by bnad, we don't expect
  715. * any other event during these states
  716. */
  717. default:
  718. bfa_sm_fault(rxf->rx->bna, event);
  719. }
  720. }
  721. static void
  722. bna_rxf_sm_resume_wait_entry(struct bna_rxf *rxf)
  723. {
  724. rxf->rxf_flags &= ~(BNA_RXF_FL_OPERSTATE_CHANGED);
  725. rxf->rxf_flags |= BNA_RXF_FL_RXF_ENABLED;
  726. __rxf_enable(rxf);
  727. }
  728. static void
  729. bna_rxf_sm_resume_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  730. {
  731. switch (event) {
  732. case RXF_E_FAIL:
  733. /**
  734. * FSM was in the process of disabling rxf, initiated by
  735. * bnad.
  736. */
  737. call_rxf_resume_cbfn(rxf, BNA_CB_FAIL);
  738. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  739. break;
  740. case RXF_E_STARTED:
  741. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  742. call_rxf_resume_cbfn(rxf, BNA_CB_SUCCESS);
  743. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  744. break;
  745. /*
  746. * Since PAUSE/RESUME can only be sent by bnad, we don't expect
  747. * any other event during these states
  748. */
  749. default:
  750. bfa_sm_fault(rxf->rx->bna, event);
  751. }
  752. }
  753. static void
  754. bna_rxf_sm_stat_clr_wait_entry(struct bna_rxf *rxf)
  755. {
  756. __bna_rxf_stat_clr(rxf);
  757. }
  758. static void
  759. bna_rxf_sm_stat_clr_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  760. {
  761. switch (event) {
  762. case RXF_E_FAIL:
  763. case RXF_E_STAT_CLEARED:
  764. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  765. break;
  766. default:
  767. bfa_sm_fault(rxf->rx->bna, event);
  768. }
  769. }
  770. static void
  771. __rxf_enable(struct bna_rxf *rxf)
  772. {
  773. struct bfi_ll_rxf_multi_req ll_req;
  774. u32 bm[2] = {0, 0};
  775. if (rxf->rxf_id < 32)
  776. bm[0] = 1 << rxf->rxf_id;
  777. else
  778. bm[1] = 1 << (rxf->rxf_id - 32);
  779. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RX_REQ, 0);
  780. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  781. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  782. ll_req.enable = 1;
  783. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  784. rxf_cb_enabled, rxf);
  785. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  786. }
  787. static void
  788. __rxf_disable(struct bna_rxf *rxf)
  789. {
  790. struct bfi_ll_rxf_multi_req ll_req;
  791. u32 bm[2] = {0, 0};
  792. if (rxf->rxf_id < 32)
  793. bm[0] = 1 << rxf->rxf_id;
  794. else
  795. bm[1] = 1 << (rxf->rxf_id - 32);
  796. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RX_REQ, 0);
  797. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  798. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  799. ll_req.enable = 0;
  800. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  801. rxf_cb_disabled, rxf);
  802. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  803. }
  804. static void
  805. __rxf_config_set(struct bna_rxf *rxf)
  806. {
  807. u32 i;
  808. struct bna_rss_mem *rss_mem;
  809. struct bna_rx_fndb_ram *rx_fndb_ram;
  810. struct bna *bna = rxf->rx->bna;
  811. void __iomem *base_addr;
  812. unsigned long off;
  813. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  814. RSS_TABLE_BASE_OFFSET);
  815. rss_mem = (struct bna_rss_mem *)0;
  816. /* Configure RSS if required */
  817. if (rxf->ctrl_flags & BNA_RXF_CF_RSS_ENABLE) {
  818. /* configure RSS Table */
  819. writel(BNA_GET_PAGE_NUM(RAD0_MEM_BLK_BASE_PG_NUM +
  820. bna->port_num, RSS_TABLE_BASE_OFFSET),
  821. bna->regs.page_addr);
  822. /* temporarily disable RSS, while hash value is written */
  823. off = (unsigned long)&rss_mem[0].type_n_hash;
  824. writel(0, base_addr + off);
  825. for (i = 0; i < BFI_RSS_HASH_KEY_LEN; i++) {
  826. off = (unsigned long)
  827. &rss_mem[0].hash_key[(BFI_RSS_HASH_KEY_LEN - 1) - i];
  828. writel(htonl(rxf->rss_cfg.toeplitz_hash_key[i]),
  829. base_addr + off);
  830. }
  831. off = (unsigned long)&rss_mem[0].type_n_hash;
  832. writel(rxf->rss_cfg.hash_type | rxf->rss_cfg.hash_mask,
  833. base_addr + off);
  834. }
  835. /* Configure RxF */
  836. writel(BNA_GET_PAGE_NUM(
  837. LUT0_MEM_BLK_BASE_PG_NUM + (bna->port_num * 2),
  838. RX_FNDB_RAM_BASE_OFFSET),
  839. bna->regs.page_addr);
  840. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  841. RX_FNDB_RAM_BASE_OFFSET);
  842. rx_fndb_ram = (struct bna_rx_fndb_ram *)0;
  843. /* We always use RSS table 0 */
  844. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].rss_prop;
  845. writel(rxf->ctrl_flags & BNA_RXF_CF_RSS_ENABLE,
  846. base_addr + off);
  847. /* small large buffer enable/disable */
  848. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].size_routing_props;
  849. writel((rxf->ctrl_flags & BNA_RXF_CF_SM_LG_RXQ) | 0x80,
  850. base_addr + off);
  851. /* RIT offset, HDS forced offset, multicast RxQ Id */
  852. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].rit_hds_mcastq;
  853. writel((rxf->rit_segment->rit_offset << 16) |
  854. (rxf->forced_offset << 8) |
  855. (rxf->hds_cfg.hdr_type & BNA_HDS_FORCED) | rxf->mcast_rxq_id,
  856. base_addr + off);
  857. /*
  858. * default vlan tag, default function enable, strip vlan bytes,
  859. * HDS type, header size
  860. */
  861. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].control_flags;
  862. writel(((u32)rxf->default_vlan_tag << 16) |
  863. (rxf->ctrl_flags &
  864. (BNA_RXF_CF_DEFAULT_VLAN |
  865. BNA_RXF_CF_DEFAULT_FUNCTION_ENABLE |
  866. BNA_RXF_CF_VLAN_STRIP)) |
  867. (rxf->hds_cfg.hdr_type & ~BNA_HDS_FORCED) |
  868. rxf->hds_cfg.header_size,
  869. base_addr + off);
  870. }
  871. void
  872. __rxf_vlan_filter_set(struct bna_rxf *rxf, enum bna_status status)
  873. {
  874. struct bna *bna = rxf->rx->bna;
  875. int i;
  876. writel(BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  877. (bna->port_num * 2), VLAN_RAM_BASE_OFFSET),
  878. bna->regs.page_addr);
  879. if (status == BNA_STATUS_T_ENABLED) {
  880. /* enable VLAN filtering on this function */
  881. for (i = 0; i <= BFI_MAX_VLAN / 32; i++) {
  882. writel(rxf->vlan_filter_table[i],
  883. BNA_GET_VLAN_MEM_ENTRY_ADDR
  884. (bna->pcidev.pci_bar_kva, rxf->rxf_id,
  885. i * 32));
  886. }
  887. } else {
  888. /* disable VLAN filtering on this function */
  889. for (i = 0; i <= BFI_MAX_VLAN / 32; i++) {
  890. writel(0xffffffff,
  891. BNA_GET_VLAN_MEM_ENTRY_ADDR
  892. (bna->pcidev.pci_bar_kva, rxf->rxf_id,
  893. i * 32));
  894. }
  895. }
  896. }
  897. static void
  898. __rxf_rit_set(struct bna_rxf *rxf)
  899. {
  900. struct bna *bna = rxf->rx->bna;
  901. struct bna_rit_mem *rit_mem;
  902. int i;
  903. void __iomem *base_addr;
  904. unsigned long off;
  905. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  906. FUNCTION_TO_RXQ_TRANSLATE);
  907. rit_mem = (struct bna_rit_mem *)0;
  908. writel(BNA_GET_PAGE_NUM(RXA0_MEM_BLK_BASE_PG_NUM + bna->port_num,
  909. FUNCTION_TO_RXQ_TRANSLATE),
  910. bna->regs.page_addr);
  911. for (i = 0; i < rxf->rit_segment->rit_size; i++) {
  912. off = (unsigned long)&rit_mem[i + rxf->rit_segment->rit_offset];
  913. writel(rxf->rit_segment->rit[i].large_rxq_id << 6 |
  914. rxf->rit_segment->rit[i].small_rxq_id,
  915. base_addr + off);
  916. }
  917. }
  918. static void
  919. __bna_rxf_stat_clr(struct bna_rxf *rxf)
  920. {
  921. struct bfi_ll_stats_req ll_req;
  922. u32 bm[2] = {0, 0};
  923. if (rxf->rxf_id < 32)
  924. bm[0] = 1 << rxf->rxf_id;
  925. else
  926. bm[1] = 1 << (rxf->rxf_id - 32);
  927. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_CLEAR_REQ, 0);
  928. ll_req.stats_mask = 0;
  929. ll_req.txf_id_mask[0] = 0;
  930. ll_req.txf_id_mask[1] = 0;
  931. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  932. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  933. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  934. bna_rxf_cb_stats_cleared, rxf);
  935. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  936. }
  937. static void
  938. rxf_enable(struct bna_rxf *rxf)
  939. {
  940. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  941. bfa_fsm_send_event(rxf, RXF_E_STARTED);
  942. else {
  943. rxf->rxf_flags |= BNA_RXF_FL_RXF_ENABLED;
  944. __rxf_enable(rxf);
  945. }
  946. }
  947. static void
  948. rxf_cb_enabled(void *arg, int status)
  949. {
  950. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  951. bfa_q_qe_init(&rxf->mbox_qe.qe);
  952. bfa_fsm_send_event(rxf, RXF_E_STARTED);
  953. }
  954. static void
  955. rxf_disable(struct bna_rxf *rxf)
  956. {
  957. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  958. bfa_fsm_send_event(rxf, RXF_E_STOPPED);
  959. else
  960. rxf->rxf_flags &= ~BNA_RXF_FL_RXF_ENABLED;
  961. __rxf_disable(rxf);
  962. }
  963. static void
  964. rxf_cb_disabled(void *arg, int status)
  965. {
  966. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  967. bfa_q_qe_init(&rxf->mbox_qe.qe);
  968. bfa_fsm_send_event(rxf, RXF_E_STOPPED);
  969. }
  970. void
  971. rxf_cb_cam_fltr_mbox_cmd(void *arg, int status)
  972. {
  973. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  974. bfa_q_qe_init(&rxf->mbox_qe.qe);
  975. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_RESP);
  976. }
  977. static void
  978. bna_rxf_cb_stats_cleared(void *arg, int status)
  979. {
  980. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  981. bfa_q_qe_init(&rxf->mbox_qe.qe);
  982. bfa_fsm_send_event(rxf, RXF_E_STAT_CLEARED);
  983. }
  984. void
  985. rxf_cam_mbox_cmd(struct bna_rxf *rxf, u8 cmd,
  986. const struct bna_mac *mac_addr)
  987. {
  988. struct bfi_ll_mac_addr_req req;
  989. bfi_h2i_set(req.mh, BFI_MC_LL, cmd, 0);
  990. req.rxf_id = rxf->rxf_id;
  991. memcpy(&req.mac_addr, (void *)&mac_addr->addr, ETH_ALEN);
  992. bna_mbox_qe_fill(&rxf->mbox_qe, &req, sizeof(req),
  993. rxf_cb_cam_fltr_mbox_cmd, rxf);
  994. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  995. }
  996. static int
  997. rxf_process_packet_filter_mcast(struct bna_rxf *rxf)
  998. {
  999. struct bna_mac *mac = NULL;
  1000. struct list_head *qe;
  1001. /* Add multicast entries */
  1002. if (!list_empty(&rxf->mcast_pending_add_q)) {
  1003. bfa_q_deq(&rxf->mcast_pending_add_q, &qe);
  1004. bfa_q_qe_init(qe);
  1005. mac = (struct bna_mac *)qe;
  1006. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_ADD_REQ, mac);
  1007. list_add_tail(&mac->qe, &rxf->mcast_active_q);
  1008. return 1;
  1009. }
  1010. /* Delete multicast entries previousely added */
  1011. if (!list_empty(&rxf->mcast_pending_del_q)) {
  1012. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1013. bfa_q_qe_init(qe);
  1014. mac = (struct bna_mac *)qe;
  1015. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1016. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1017. return 1;
  1018. }
  1019. return 0;
  1020. }
  1021. static int
  1022. rxf_process_packet_filter_vlan(struct bna_rxf *rxf)
  1023. {
  1024. /* Apply the VLAN filter */
  1025. if (rxf->rxf_flags & BNA_RXF_FL_VLAN_CONFIG_PENDING) {
  1026. rxf->rxf_flags &= ~BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1027. if (!(rxf->rxmode_active & BNA_RXMODE_PROMISC))
  1028. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1029. }
  1030. /* Apply RSS configuration */
  1031. if (rxf->rxf_flags & BNA_RXF_FL_RSS_CONFIG_PENDING) {
  1032. rxf->rxf_flags &= ~BNA_RXF_FL_RSS_CONFIG_PENDING;
  1033. if (rxf->rss_status == BNA_STATUS_T_DISABLED) {
  1034. /* RSS is being disabled */
  1035. rxf->ctrl_flags &= ~BNA_RXF_CF_RSS_ENABLE;
  1036. __rxf_rit_set(rxf);
  1037. __rxf_config_set(rxf);
  1038. } else {
  1039. /* RSS is being enabled or reconfigured */
  1040. rxf->ctrl_flags |= BNA_RXF_CF_RSS_ENABLE;
  1041. __rxf_rit_set(rxf);
  1042. __rxf_config_set(rxf);
  1043. }
  1044. }
  1045. return 0;
  1046. }
  1047. /**
  1048. * Processes pending ucast, mcast entry addition/deletion and issues mailbox
  1049. * command. Also processes pending filter configuration - promiscuous mode,
  1050. * default mode, allmutli mode and issues mailbox command or directly applies
  1051. * to h/w
  1052. */
  1053. static int
  1054. rxf_process_packet_filter(struct bna_rxf *rxf)
  1055. {
  1056. /* Set the default MAC first */
  1057. if (rxf->ucast_pending_set > 0) {
  1058. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_SET_REQ,
  1059. rxf->ucast_active_mac);
  1060. rxf->ucast_pending_set--;
  1061. return 1;
  1062. }
  1063. if (rxf_process_packet_filter_ucast(rxf))
  1064. return 1;
  1065. if (rxf_process_packet_filter_mcast(rxf))
  1066. return 1;
  1067. if (rxf_process_packet_filter_promisc(rxf))
  1068. return 1;
  1069. if (rxf_process_packet_filter_allmulti(rxf))
  1070. return 1;
  1071. if (rxf_process_packet_filter_vlan(rxf))
  1072. return 1;
  1073. return 0;
  1074. }
  1075. static int
  1076. rxf_clear_packet_filter_mcast(struct bna_rxf *rxf)
  1077. {
  1078. struct bna_mac *mac = NULL;
  1079. struct list_head *qe;
  1080. /* 3. delete pending mcast entries */
  1081. if (!list_empty(&rxf->mcast_pending_del_q)) {
  1082. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1083. bfa_q_qe_init(qe);
  1084. mac = (struct bna_mac *)qe;
  1085. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1086. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1087. return 1;
  1088. }
  1089. /* 4. clear active mcast entries; move them to pending_add_q */
  1090. if (!list_empty(&rxf->mcast_active_q)) {
  1091. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1092. bfa_q_qe_init(qe);
  1093. mac = (struct bna_mac *)qe;
  1094. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1095. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1096. return 1;
  1097. }
  1098. return 0;
  1099. }
  1100. /**
  1101. * In the rxf stop path, processes pending ucast/mcast delete queue and issues
  1102. * the mailbox command. Moves the active ucast/mcast entries to pending add q,
  1103. * so that they are added to CAM again in the rxf start path. Moves the current
  1104. * filter settings - promiscuous, default, allmutli - to pending filter
  1105. * configuration
  1106. */
  1107. static int
  1108. rxf_clear_packet_filter(struct bna_rxf *rxf)
  1109. {
  1110. if (rxf_clear_packet_filter_ucast(rxf))
  1111. return 1;
  1112. if (rxf_clear_packet_filter_mcast(rxf))
  1113. return 1;
  1114. /* 5. clear active default MAC in the CAM */
  1115. if (rxf->ucast_pending_set > 0)
  1116. rxf->ucast_pending_set = 0;
  1117. if (rxf_clear_packet_filter_promisc(rxf))
  1118. return 1;
  1119. if (rxf_clear_packet_filter_allmulti(rxf))
  1120. return 1;
  1121. return 0;
  1122. }
  1123. static void
  1124. rxf_reset_packet_filter_mcast(struct bna_rxf *rxf)
  1125. {
  1126. struct list_head *qe;
  1127. struct bna_mac *mac;
  1128. /* 3. Move active mcast entries to pending_add_q */
  1129. while (!list_empty(&rxf->mcast_active_q)) {
  1130. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1131. bfa_q_qe_init(qe);
  1132. list_add_tail(qe, &rxf->mcast_pending_add_q);
  1133. }
  1134. /* 4. Throw away delete pending mcast entries */
  1135. while (!list_empty(&rxf->mcast_pending_del_q)) {
  1136. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1137. bfa_q_qe_init(qe);
  1138. mac = (struct bna_mac *)qe;
  1139. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1140. }
  1141. }
  1142. /**
  1143. * In the rxf fail path, throws away the ucast/mcast entries pending for
  1144. * deletion, moves all active ucast/mcast entries to pending queue so that
  1145. * they are added back to CAM in the rxf start path. Also moves the current
  1146. * filter configuration to pending filter configuration.
  1147. */
  1148. static void
  1149. rxf_reset_packet_filter(struct bna_rxf *rxf)
  1150. {
  1151. rxf_reset_packet_filter_ucast(rxf);
  1152. rxf_reset_packet_filter_mcast(rxf);
  1153. /* 5. Turn off ucast set flag */
  1154. rxf->ucast_pending_set = 0;
  1155. rxf_reset_packet_filter_promisc(rxf);
  1156. rxf_reset_packet_filter_allmulti(rxf);
  1157. }
  1158. static void
  1159. bna_rxf_init(struct bna_rxf *rxf,
  1160. struct bna_rx *rx,
  1161. struct bna_rx_config *q_config)
  1162. {
  1163. struct list_head *qe;
  1164. struct bna_rxp *rxp;
  1165. /* rxf_id is initialized during rx_mod init */
  1166. rxf->rx = rx;
  1167. INIT_LIST_HEAD(&rxf->ucast_pending_add_q);
  1168. INIT_LIST_HEAD(&rxf->ucast_pending_del_q);
  1169. rxf->ucast_pending_set = 0;
  1170. INIT_LIST_HEAD(&rxf->ucast_active_q);
  1171. rxf->ucast_active_mac = NULL;
  1172. INIT_LIST_HEAD(&rxf->mcast_pending_add_q);
  1173. INIT_LIST_HEAD(&rxf->mcast_pending_del_q);
  1174. INIT_LIST_HEAD(&rxf->mcast_active_q);
  1175. bfa_q_qe_init(&rxf->mbox_qe.qe);
  1176. if (q_config->vlan_strip_status == BNA_STATUS_T_ENABLED)
  1177. rxf->ctrl_flags |= BNA_RXF_CF_VLAN_STRIP;
  1178. rxf->rxf_oper_state = (q_config->paused) ?
  1179. BNA_RXF_OPER_STATE_PAUSED : BNA_RXF_OPER_STATE_RUNNING;
  1180. bna_rxf_adv_init(rxf, rx, q_config);
  1181. rxf->rit_segment = bna_rit_mod_seg_get(&rxf->rx->bna->rit_mod,
  1182. q_config->num_paths);
  1183. list_for_each(qe, &rx->rxp_q) {
  1184. rxp = (struct bna_rxp *)qe;
  1185. if (q_config->rxp_type == BNA_RXP_SINGLE)
  1186. rxf->mcast_rxq_id = rxp->rxq.single.only->rxq_id;
  1187. else
  1188. rxf->mcast_rxq_id = rxp->rxq.slr.large->rxq_id;
  1189. break;
  1190. }
  1191. rxf->vlan_filter_status = BNA_STATUS_T_DISABLED;
  1192. memset(rxf->vlan_filter_table, 0,
  1193. (sizeof(u32) * ((BFI_MAX_VLAN + 1) / 32)));
  1194. /* Set up VLAN 0 for pure priority tagged packets */
  1195. rxf->vlan_filter_table[0] |= 1;
  1196. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  1197. }
  1198. static void
  1199. bna_rxf_uninit(struct bna_rxf *rxf)
  1200. {
  1201. struct bna *bna = rxf->rx->bna;
  1202. struct bna_mac *mac;
  1203. bna_rit_mod_seg_put(&rxf->rx->bna->rit_mod, rxf->rit_segment);
  1204. rxf->rit_segment = NULL;
  1205. rxf->ucast_pending_set = 0;
  1206. while (!list_empty(&rxf->ucast_pending_add_q)) {
  1207. bfa_q_deq(&rxf->ucast_pending_add_q, &mac);
  1208. bfa_q_qe_init(&mac->qe);
  1209. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1210. }
  1211. if (rxf->ucast_active_mac) {
  1212. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1213. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod,
  1214. rxf->ucast_active_mac);
  1215. rxf->ucast_active_mac = NULL;
  1216. }
  1217. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1218. bfa_q_deq(&rxf->mcast_pending_add_q, &mac);
  1219. bfa_q_qe_init(&mac->qe);
  1220. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1221. }
  1222. /* Turn off pending promisc mode */
  1223. if (is_promisc_enable(rxf->rxmode_pending,
  1224. rxf->rxmode_pending_bitmask)) {
  1225. /* system promisc state should be pending */
  1226. BUG_ON(!(bna->rxf_promisc_id == rxf->rxf_id));
  1227. promisc_inactive(rxf->rxmode_pending,
  1228. rxf->rxmode_pending_bitmask);
  1229. bna->rxf_promisc_id = BFI_MAX_RXF;
  1230. }
  1231. /* Promisc mode should not be active */
  1232. BUG_ON(rxf->rxmode_active & BNA_RXMODE_PROMISC);
  1233. /* Turn off pending all-multi mode */
  1234. if (is_allmulti_enable(rxf->rxmode_pending,
  1235. rxf->rxmode_pending_bitmask)) {
  1236. allmulti_inactive(rxf->rxmode_pending,
  1237. rxf->rxmode_pending_bitmask);
  1238. }
  1239. /* Allmulti mode should not be active */
  1240. BUG_ON(rxf->rxmode_active & BNA_RXMODE_ALLMULTI);
  1241. rxf->rx = NULL;
  1242. }
  1243. static void
  1244. bna_rx_cb_rxf_started(struct bna_rx *rx, enum bna_cb_status status)
  1245. {
  1246. bfa_fsm_send_event(rx, RX_E_RXF_STARTED);
  1247. if (rx->rxf.rxf_id < 32)
  1248. rx->bna->rx_mod.rxf_bmap[0] |= ((u32)1 << rx->rxf.rxf_id);
  1249. else
  1250. rx->bna->rx_mod.rxf_bmap[1] |= ((u32)
  1251. 1 << (rx->rxf.rxf_id - 32));
  1252. }
  1253. static void
  1254. bna_rxf_start(struct bna_rxf *rxf)
  1255. {
  1256. rxf->start_cbfn = bna_rx_cb_rxf_started;
  1257. rxf->start_cbarg = rxf->rx;
  1258. rxf->rxf_flags &= ~BNA_RXF_FL_FAILED;
  1259. bfa_fsm_send_event(rxf, RXF_E_START);
  1260. }
  1261. static void
  1262. bna_rx_cb_rxf_stopped(struct bna_rx *rx, enum bna_cb_status status)
  1263. {
  1264. bfa_fsm_send_event(rx, RX_E_RXF_STOPPED);
  1265. if (rx->rxf.rxf_id < 32)
  1266. rx->bna->rx_mod.rxf_bmap[0] &= ~(u32)1 << rx->rxf.rxf_id;
  1267. else
  1268. rx->bna->rx_mod.rxf_bmap[1] &= ~(u32)
  1269. 1 << (rx->rxf.rxf_id - 32);
  1270. }
  1271. static void
  1272. bna_rxf_stop(struct bna_rxf *rxf)
  1273. {
  1274. rxf->stop_cbfn = bna_rx_cb_rxf_stopped;
  1275. rxf->stop_cbarg = rxf->rx;
  1276. bfa_fsm_send_event(rxf, RXF_E_STOP);
  1277. }
  1278. static void
  1279. bna_rxf_fail(struct bna_rxf *rxf)
  1280. {
  1281. rxf->rxf_flags |= BNA_RXF_FL_FAILED;
  1282. bfa_fsm_send_event(rxf, RXF_E_FAIL);
  1283. }
  1284. int
  1285. bna_rxf_state_get(struct bna_rxf *rxf)
  1286. {
  1287. return bfa_sm_to_state(rxf_sm_table, rxf->fsm);
  1288. }
  1289. enum bna_cb_status
  1290. bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
  1291. void (*cbfn)(struct bnad *, struct bna_rx *,
  1292. enum bna_cb_status))
  1293. {
  1294. struct bna_rxf *rxf = &rx->rxf;
  1295. if (rxf->ucast_active_mac == NULL) {
  1296. rxf->ucast_active_mac =
  1297. bna_ucam_mod_mac_get(&rxf->rx->bna->ucam_mod);
  1298. if (rxf->ucast_active_mac == NULL)
  1299. return BNA_CB_UCAST_CAM_FULL;
  1300. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1301. }
  1302. memcpy(rxf->ucast_active_mac->addr, ucmac, ETH_ALEN);
  1303. rxf->ucast_pending_set++;
  1304. rxf->cam_fltr_cbfn = cbfn;
  1305. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1306. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1307. return BNA_CB_SUCCESS;
  1308. }
  1309. enum bna_cb_status
  1310. bna_rx_mcast_add(struct bna_rx *rx, u8 *addr,
  1311. void (*cbfn)(struct bnad *, struct bna_rx *,
  1312. enum bna_cb_status))
  1313. {
  1314. struct bna_rxf *rxf = &rx->rxf;
  1315. struct list_head *qe;
  1316. struct bna_mac *mac;
  1317. /* Check if already added */
  1318. list_for_each(qe, &rxf->mcast_active_q) {
  1319. mac = (struct bna_mac *)qe;
  1320. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1321. if (cbfn)
  1322. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1323. return BNA_CB_SUCCESS;
  1324. }
  1325. }
  1326. /* Check if pending addition */
  1327. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1328. mac = (struct bna_mac *)qe;
  1329. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1330. if (cbfn)
  1331. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1332. return BNA_CB_SUCCESS;
  1333. }
  1334. }
  1335. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1336. if (mac == NULL)
  1337. return BNA_CB_MCAST_LIST_FULL;
  1338. bfa_q_qe_init(&mac->qe);
  1339. memcpy(mac->addr, addr, ETH_ALEN);
  1340. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1341. rxf->cam_fltr_cbfn = cbfn;
  1342. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1343. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1344. return BNA_CB_SUCCESS;
  1345. }
  1346. enum bna_cb_status
  1347. bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mclist,
  1348. void (*cbfn)(struct bnad *, struct bna_rx *,
  1349. enum bna_cb_status))
  1350. {
  1351. struct bna_rxf *rxf = &rx->rxf;
  1352. struct list_head list_head;
  1353. struct list_head *qe;
  1354. u8 *mcaddr;
  1355. struct bna_mac *mac;
  1356. struct bna_mac *mac1;
  1357. int skip;
  1358. int delete;
  1359. int need_hw_config = 0;
  1360. int i;
  1361. /* Allocate nodes */
  1362. INIT_LIST_HEAD(&list_head);
  1363. for (i = 0, mcaddr = mclist; i < count; i++) {
  1364. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1365. if (mac == NULL)
  1366. goto err_return;
  1367. bfa_q_qe_init(&mac->qe);
  1368. memcpy(mac->addr, mcaddr, ETH_ALEN);
  1369. list_add_tail(&mac->qe, &list_head);
  1370. mcaddr += ETH_ALEN;
  1371. }
  1372. /* Schedule for addition */
  1373. while (!list_empty(&list_head)) {
  1374. bfa_q_deq(&list_head, &qe);
  1375. mac = (struct bna_mac *)qe;
  1376. bfa_q_qe_init(&mac->qe);
  1377. skip = 0;
  1378. /* Skip if already added */
  1379. list_for_each(qe, &rxf->mcast_active_q) {
  1380. mac1 = (struct bna_mac *)qe;
  1381. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1382. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1383. mac);
  1384. skip = 1;
  1385. break;
  1386. }
  1387. }
  1388. if (skip)
  1389. continue;
  1390. /* Skip if pending addition */
  1391. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1392. mac1 = (struct bna_mac *)qe;
  1393. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1394. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1395. mac);
  1396. skip = 1;
  1397. break;
  1398. }
  1399. }
  1400. if (skip)
  1401. continue;
  1402. need_hw_config = 1;
  1403. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1404. }
  1405. /**
  1406. * Delete the entries that are in the pending_add_q but not
  1407. * in the new list
  1408. */
  1409. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1410. bfa_q_deq(&rxf->mcast_pending_add_q, &qe);
  1411. mac = (struct bna_mac *)qe;
  1412. bfa_q_qe_init(&mac->qe);
  1413. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1414. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1415. delete = 0;
  1416. break;
  1417. }
  1418. mcaddr += ETH_ALEN;
  1419. }
  1420. if (delete)
  1421. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1422. else
  1423. list_add_tail(&mac->qe, &list_head);
  1424. }
  1425. while (!list_empty(&list_head)) {
  1426. bfa_q_deq(&list_head, &qe);
  1427. mac = (struct bna_mac *)qe;
  1428. bfa_q_qe_init(&mac->qe);
  1429. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1430. }
  1431. /**
  1432. * Schedule entries for deletion that are in the active_q but not
  1433. * in the new list
  1434. */
  1435. while (!list_empty(&rxf->mcast_active_q)) {
  1436. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1437. mac = (struct bna_mac *)qe;
  1438. bfa_q_qe_init(&mac->qe);
  1439. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1440. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1441. delete = 0;
  1442. break;
  1443. }
  1444. mcaddr += ETH_ALEN;
  1445. }
  1446. if (delete) {
  1447. list_add_tail(&mac->qe, &rxf->mcast_pending_del_q);
  1448. need_hw_config = 1;
  1449. } else {
  1450. list_add_tail(&mac->qe, &list_head);
  1451. }
  1452. }
  1453. while (!list_empty(&list_head)) {
  1454. bfa_q_deq(&list_head, &qe);
  1455. mac = (struct bna_mac *)qe;
  1456. bfa_q_qe_init(&mac->qe);
  1457. list_add_tail(&mac->qe, &rxf->mcast_active_q);
  1458. }
  1459. if (need_hw_config) {
  1460. rxf->cam_fltr_cbfn = cbfn;
  1461. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1462. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1463. } else if (cbfn)
  1464. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1465. return BNA_CB_SUCCESS;
  1466. err_return:
  1467. while (!list_empty(&list_head)) {
  1468. bfa_q_deq(&list_head, &qe);
  1469. mac = (struct bna_mac *)qe;
  1470. bfa_q_qe_init(&mac->qe);
  1471. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1472. }
  1473. return BNA_CB_MCAST_LIST_FULL;
  1474. }
  1475. void
  1476. bna_rx_vlan_add(struct bna_rx *rx, int vlan_id)
  1477. {
  1478. struct bna_rxf *rxf = &rx->rxf;
  1479. int index = (vlan_id >> 5);
  1480. int bit = (1 << (vlan_id & 0x1F));
  1481. rxf->vlan_filter_table[index] |= bit;
  1482. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1483. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1484. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1485. }
  1486. }
  1487. void
  1488. bna_rx_vlan_del(struct bna_rx *rx, int vlan_id)
  1489. {
  1490. struct bna_rxf *rxf = &rx->rxf;
  1491. int index = (vlan_id >> 5);
  1492. int bit = (1 << (vlan_id & 0x1F));
  1493. rxf->vlan_filter_table[index] &= ~bit;
  1494. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1495. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1496. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1497. }
  1498. }
  1499. /**
  1500. * RX
  1501. */
  1502. #define RXQ_RCB_INIT(q, rxp, qdepth, bna, _id, unmapq_mem) do { \
  1503. struct bna_doorbell_qset *_qset; \
  1504. unsigned long off; \
  1505. (q)->rcb->producer_index = (q)->rcb->consumer_index = 0; \
  1506. (q)->rcb->q_depth = (qdepth); \
  1507. (q)->rcb->unmap_q = unmapq_mem; \
  1508. (q)->rcb->rxq = (q); \
  1509. (q)->rcb->cq = &(rxp)->cq; \
  1510. (q)->rcb->bnad = (bna)->bnad; \
  1511. _qset = (struct bna_doorbell_qset *)0; \
  1512. off = (unsigned long)&_qset[(q)->rxq_id].rxq[0]; \
  1513. (q)->rcb->q_dbell = off + \
  1514. BNA_GET_DOORBELL_BASE_ADDR((bna)->pcidev.pci_bar_kva); \
  1515. (q)->rcb->id = _id; \
  1516. } while (0)
  1517. #define BNA_GET_RXQS(qcfg) (((qcfg)->rxp_type == BNA_RXP_SINGLE) ? \
  1518. (qcfg)->num_paths : ((qcfg)->num_paths * 2))
  1519. #define SIZE_TO_PAGES(size) (((size) >> PAGE_SHIFT) + ((((size) &\
  1520. (PAGE_SIZE - 1)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  1521. #define call_rx_stop_callback(rx, status) \
  1522. if ((rx)->stop_cbfn) { \
  1523. (*(rx)->stop_cbfn)((rx)->stop_cbarg, rx, (status)); \
  1524. (rx)->stop_cbfn = NULL; \
  1525. (rx)->stop_cbarg = NULL; \
  1526. }
  1527. /*
  1528. * Since rx_enable is synchronous callback, there is no start_cbfn required.
  1529. * Instead, we'll call bnad_rx_post(rxp) so that bnad can post the buffers
  1530. * for each rxpath.
  1531. */
  1532. #define call_rx_disable_cbfn(rx, status) \
  1533. if ((rx)->disable_cbfn) { \
  1534. (*(rx)->disable_cbfn)((rx)->disable_cbarg, \
  1535. status); \
  1536. (rx)->disable_cbfn = NULL; \
  1537. (rx)->disable_cbarg = NULL; \
  1538. } \
  1539. #define rxqs_reqd(type, num_rxqs) \
  1540. (((type) == BNA_RXP_SINGLE) ? (num_rxqs) : ((num_rxqs) * 2))
  1541. #define rx_ib_fail(rx) \
  1542. do { \
  1543. struct bna_rxp *rxp; \
  1544. struct list_head *qe; \
  1545. list_for_each(qe, &(rx)->rxp_q) { \
  1546. rxp = (struct bna_rxp *)qe; \
  1547. bna_ib_fail(rxp->cq.ib); \
  1548. } \
  1549. } while (0)
  1550. static void __bna_multi_rxq_stop(struct bna_rxp *, u32 *);
  1551. static void __bna_rxq_start(struct bna_rxq *rxq);
  1552. static void __bna_cq_start(struct bna_cq *cq);
  1553. static void bna_rit_create(struct bna_rx *rx);
  1554. static void bna_rx_cb_multi_rxq_stopped(void *arg, int status);
  1555. static void bna_rx_cb_rxq_stopped_all(void *arg);
  1556. bfa_fsm_state_decl(bna_rx, stopped,
  1557. struct bna_rx, enum bna_rx_event);
  1558. bfa_fsm_state_decl(bna_rx, rxf_start_wait,
  1559. struct bna_rx, enum bna_rx_event);
  1560. bfa_fsm_state_decl(bna_rx, started,
  1561. struct bna_rx, enum bna_rx_event);
  1562. bfa_fsm_state_decl(bna_rx, rxf_stop_wait,
  1563. struct bna_rx, enum bna_rx_event);
  1564. bfa_fsm_state_decl(bna_rx, rxq_stop_wait,
  1565. struct bna_rx, enum bna_rx_event);
  1566. static const struct bfa_sm_table rx_sm_table[] = {
  1567. {BFA_SM(bna_rx_sm_stopped), BNA_RX_STOPPED},
  1568. {BFA_SM(bna_rx_sm_rxf_start_wait), BNA_RX_RXF_START_WAIT},
  1569. {BFA_SM(bna_rx_sm_started), BNA_RX_STARTED},
  1570. {BFA_SM(bna_rx_sm_rxf_stop_wait), BNA_RX_RXF_STOP_WAIT},
  1571. {BFA_SM(bna_rx_sm_rxq_stop_wait), BNA_RX_RXQ_STOP_WAIT},
  1572. };
  1573. static void bna_rx_sm_stopped_entry(struct bna_rx *rx)
  1574. {
  1575. struct bna_rxp *rxp;
  1576. struct list_head *qe_rxp;
  1577. list_for_each(qe_rxp, &rx->rxp_q) {
  1578. rxp = (struct bna_rxp *)qe_rxp;
  1579. rx->rx_cleanup_cbfn(rx->bna->bnad, rxp->cq.ccb);
  1580. }
  1581. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1582. }
  1583. static void bna_rx_sm_stopped(struct bna_rx *rx,
  1584. enum bna_rx_event event)
  1585. {
  1586. switch (event) {
  1587. case RX_E_START:
  1588. bfa_fsm_set_state(rx, bna_rx_sm_rxf_start_wait);
  1589. break;
  1590. case RX_E_STOP:
  1591. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1592. break;
  1593. case RX_E_FAIL:
  1594. /* no-op */
  1595. break;
  1596. default:
  1597. bfa_sm_fault(rx->bna, event);
  1598. break;
  1599. }
  1600. }
  1601. static void bna_rx_sm_rxf_start_wait_entry(struct bna_rx *rx)
  1602. {
  1603. struct bna_rxp *rxp;
  1604. struct list_head *qe_rxp;
  1605. struct bna_rxq *q0 = NULL, *q1 = NULL;
  1606. /* Setup the RIT */
  1607. bna_rit_create(rx);
  1608. list_for_each(qe_rxp, &rx->rxp_q) {
  1609. rxp = (struct bna_rxp *)qe_rxp;
  1610. bna_ib_start(rxp->cq.ib);
  1611. GET_RXQS(rxp, q0, q1);
  1612. q0->buffer_size = bna_port_mtu_get(&rx->bna->port);
  1613. __bna_rxq_start(q0);
  1614. rx->rx_post_cbfn(rx->bna->bnad, q0->rcb);
  1615. if (q1) {
  1616. __bna_rxq_start(q1);
  1617. rx->rx_post_cbfn(rx->bna->bnad, q1->rcb);
  1618. }
  1619. __bna_cq_start(&rxp->cq);
  1620. }
  1621. bna_rxf_start(&rx->rxf);
  1622. }
  1623. static void bna_rx_sm_rxf_start_wait(struct bna_rx *rx,
  1624. enum bna_rx_event event)
  1625. {
  1626. switch (event) {
  1627. case RX_E_STOP:
  1628. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1629. break;
  1630. case RX_E_FAIL:
  1631. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1632. rx_ib_fail(rx);
  1633. bna_rxf_fail(&rx->rxf);
  1634. break;
  1635. case RX_E_RXF_STARTED:
  1636. bfa_fsm_set_state(rx, bna_rx_sm_started);
  1637. break;
  1638. default:
  1639. bfa_sm_fault(rx->bna, event);
  1640. break;
  1641. }
  1642. }
  1643. void
  1644. bna_rx_sm_started_entry(struct bna_rx *rx)
  1645. {
  1646. struct bna_rxp *rxp;
  1647. struct list_head *qe_rxp;
  1648. /* Start IB */
  1649. list_for_each(qe_rxp, &rx->rxp_q) {
  1650. rxp = (struct bna_rxp *)qe_rxp;
  1651. bna_ib_ack(&rxp->cq.ib->door_bell, 0);
  1652. }
  1653. bna_llport_rx_started(&rx->bna->port.llport);
  1654. }
  1655. void
  1656. bna_rx_sm_started(struct bna_rx *rx, enum bna_rx_event event)
  1657. {
  1658. switch (event) {
  1659. case RX_E_FAIL:
  1660. bna_llport_rx_stopped(&rx->bna->port.llport);
  1661. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1662. rx_ib_fail(rx);
  1663. bna_rxf_fail(&rx->rxf);
  1664. break;
  1665. case RX_E_STOP:
  1666. bna_llport_rx_stopped(&rx->bna->port.llport);
  1667. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1668. break;
  1669. default:
  1670. bfa_sm_fault(rx->bna, event);
  1671. break;
  1672. }
  1673. }
  1674. void
  1675. bna_rx_sm_rxf_stop_wait_entry(struct bna_rx *rx)
  1676. {
  1677. bna_rxf_stop(&rx->rxf);
  1678. }
  1679. void
  1680. bna_rx_sm_rxf_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1681. {
  1682. switch (event) {
  1683. case RX_E_RXF_STOPPED:
  1684. bfa_fsm_set_state(rx, bna_rx_sm_rxq_stop_wait);
  1685. break;
  1686. case RX_E_RXF_STARTED:
  1687. /**
  1688. * RxF was in the process of starting up when
  1689. * RXF_E_STOP was issued. Ignore this event
  1690. */
  1691. break;
  1692. case RX_E_FAIL:
  1693. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1694. rx_ib_fail(rx);
  1695. bna_rxf_fail(&rx->rxf);
  1696. break;
  1697. default:
  1698. bfa_sm_fault(rx->bna, event);
  1699. break;
  1700. }
  1701. }
  1702. void
  1703. bna_rx_sm_rxq_stop_wait_entry(struct bna_rx *rx)
  1704. {
  1705. struct bna_rxp *rxp = NULL;
  1706. struct bna_rxq *q0 = NULL;
  1707. struct bna_rxq *q1 = NULL;
  1708. struct list_head *qe;
  1709. u32 rxq_mask[2] = {0, 0};
  1710. /* Only one call to multi-rxq-stop for all RXPs in this RX */
  1711. bfa_wc_up(&rx->rxq_stop_wc);
  1712. list_for_each(qe, &rx->rxp_q) {
  1713. rxp = (struct bna_rxp *)qe;
  1714. GET_RXQS(rxp, q0, q1);
  1715. if (q0->rxq_id < 32)
  1716. rxq_mask[0] |= ((u32)1 << q0->rxq_id);
  1717. else
  1718. rxq_mask[1] |= ((u32)1 << (q0->rxq_id - 32));
  1719. if (q1) {
  1720. if (q1->rxq_id < 32)
  1721. rxq_mask[0] |= ((u32)1 << q1->rxq_id);
  1722. else
  1723. rxq_mask[1] |= ((u32)
  1724. 1 << (q1->rxq_id - 32));
  1725. }
  1726. }
  1727. __bna_multi_rxq_stop(rxp, rxq_mask);
  1728. }
  1729. void
  1730. bna_rx_sm_rxq_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1731. {
  1732. struct bna_rxp *rxp = NULL;
  1733. struct list_head *qe;
  1734. switch (event) {
  1735. case RX_E_RXQ_STOPPED:
  1736. list_for_each(qe, &rx->rxp_q) {
  1737. rxp = (struct bna_rxp *)qe;
  1738. bna_ib_stop(rxp->cq.ib);
  1739. }
  1740. /* Fall through */
  1741. case RX_E_FAIL:
  1742. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1743. break;
  1744. default:
  1745. bfa_sm_fault(rx->bna, event);
  1746. break;
  1747. }
  1748. }
  1749. void
  1750. __bna_multi_rxq_stop(struct bna_rxp *rxp, u32 * rxq_id_mask)
  1751. {
  1752. struct bfi_ll_q_stop_req ll_req;
  1753. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RXQ_STOP_REQ, 0);
  1754. ll_req.q_id_mask[0] = htonl(rxq_id_mask[0]);
  1755. ll_req.q_id_mask[1] = htonl(rxq_id_mask[1]);
  1756. bna_mbox_qe_fill(&rxp->mbox_qe, &ll_req, sizeof(ll_req),
  1757. bna_rx_cb_multi_rxq_stopped, rxp);
  1758. bna_mbox_send(rxp->rx->bna, &rxp->mbox_qe);
  1759. }
  1760. void
  1761. __bna_rxq_start(struct bna_rxq *rxq)
  1762. {
  1763. struct bna_rxtx_q_mem *q_mem;
  1764. struct bna_rxq_mem rxq_cfg, *rxq_mem;
  1765. struct bna_dma_addr cur_q_addr;
  1766. /* struct bna_doorbell_qset *qset; */
  1767. struct bna_qpt *qpt;
  1768. u32 pg_num;
  1769. struct bna *bna = rxq->rx->bna;
  1770. void __iomem *base_addr;
  1771. unsigned long off;
  1772. qpt = &rxq->qpt;
  1773. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1774. rxq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1775. rxq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1776. rxq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1777. rxq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1778. rxq_cfg.pg_cnt_n_prd_ptr = ((u32)qpt->page_count << 16) | 0x0;
  1779. rxq_cfg.entry_n_pg_size = ((u32)(BFI_RXQ_WI_SIZE >> 2) << 16) |
  1780. (qpt->page_size >> 2);
  1781. rxq_cfg.sg_n_cq_n_cns_ptr =
  1782. ((u32)(rxq->rxp->cq.cq_id & 0xff) << 16) | 0x0;
  1783. rxq_cfg.buf_sz_n_q_state = ((u32)rxq->buffer_size << 16) |
  1784. BNA_Q_IDLE_STATE;
  1785. rxq_cfg.next_qid = 0x0 | (0x3 << 8);
  1786. /* Write the page number register */
  1787. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1788. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1789. writel(pg_num, bna->regs.page_addr);
  1790. /* Write to h/w */
  1791. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1792. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1793. q_mem = (struct bna_rxtx_q_mem *)0;
  1794. rxq_mem = &q_mem[rxq->rxq_id].rxq;
  1795. off = (unsigned long)&rxq_mem->pg_tbl_addr_lo;
  1796. writel(htonl(rxq_cfg.pg_tbl_addr_lo), base_addr + off);
  1797. off = (unsigned long)&rxq_mem->pg_tbl_addr_hi;
  1798. writel(htonl(rxq_cfg.pg_tbl_addr_hi), base_addr + off);
  1799. off = (unsigned long)&rxq_mem->cur_q_entry_lo;
  1800. writel(htonl(rxq_cfg.cur_q_entry_lo), base_addr + off);
  1801. off = (unsigned long)&rxq_mem->cur_q_entry_hi;
  1802. writel(htonl(rxq_cfg.cur_q_entry_hi), base_addr + off);
  1803. off = (unsigned long)&rxq_mem->pg_cnt_n_prd_ptr;
  1804. writel(rxq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1805. off = (unsigned long)&rxq_mem->entry_n_pg_size;
  1806. writel(rxq_cfg.entry_n_pg_size, base_addr + off);
  1807. off = (unsigned long)&rxq_mem->sg_n_cq_n_cns_ptr;
  1808. writel(rxq_cfg.sg_n_cq_n_cns_ptr, base_addr + off);
  1809. off = (unsigned long)&rxq_mem->buf_sz_n_q_state;
  1810. writel(rxq_cfg.buf_sz_n_q_state, base_addr + off);
  1811. off = (unsigned long)&rxq_mem->next_qid;
  1812. writel(rxq_cfg.next_qid, base_addr + off);
  1813. rxq->rcb->producer_index = 0;
  1814. rxq->rcb->consumer_index = 0;
  1815. }
  1816. void
  1817. __bna_cq_start(struct bna_cq *cq)
  1818. {
  1819. struct bna_cq_mem cq_cfg, *cq_mem;
  1820. const struct bna_qpt *qpt;
  1821. struct bna_dma_addr cur_q_addr;
  1822. u32 pg_num;
  1823. struct bna *bna = cq->rx->bna;
  1824. void __iomem *base_addr;
  1825. unsigned long off;
  1826. qpt = &cq->qpt;
  1827. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1828. /*
  1829. * Fill out structure, to be subsequently written
  1830. * to hardware
  1831. */
  1832. cq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1833. cq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1834. cq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1835. cq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1836. cq_cfg.pg_cnt_n_prd_ptr = (qpt->page_count << 16) | 0x0;
  1837. cq_cfg.entry_n_pg_size =
  1838. ((u32)(BFI_CQ_WI_SIZE >> 2) << 16) | (qpt->page_size >> 2);
  1839. cq_cfg.int_blk_n_cns_ptr = ((((u32)cq->ib_seg_offset) << 24) |
  1840. ((u32)(cq->ib->ib_id & 0xff) << 16) | 0x0);
  1841. cq_cfg.q_state = BNA_Q_IDLE_STATE;
  1842. /* Write the page number register */
  1843. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1844. HQM_CQ_RAM_BASE_OFFSET);
  1845. writel(pg_num, bna->regs.page_addr);
  1846. /* H/W write */
  1847. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1848. HQM_CQ_RAM_BASE_OFFSET);
  1849. cq_mem = (struct bna_cq_mem *)0;
  1850. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_lo;
  1851. writel(htonl(cq_cfg.pg_tbl_addr_lo), base_addr + off);
  1852. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_hi;
  1853. writel(htonl(cq_cfg.pg_tbl_addr_hi), base_addr + off);
  1854. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_lo;
  1855. writel(htonl(cq_cfg.cur_q_entry_lo), base_addr + off);
  1856. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_hi;
  1857. writel(htonl(cq_cfg.cur_q_entry_hi), base_addr + off);
  1858. off = (unsigned long)&cq_mem[cq->cq_id].pg_cnt_n_prd_ptr;
  1859. writel(cq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1860. off = (unsigned long)&cq_mem[cq->cq_id].entry_n_pg_size;
  1861. writel(cq_cfg.entry_n_pg_size, base_addr + off);
  1862. off = (unsigned long)&cq_mem[cq->cq_id].int_blk_n_cns_ptr;
  1863. writel(cq_cfg.int_blk_n_cns_ptr, base_addr + off);
  1864. off = (unsigned long)&cq_mem[cq->cq_id].q_state;
  1865. writel(cq_cfg.q_state, base_addr + off);
  1866. cq->ccb->producer_index = 0;
  1867. *(cq->ccb->hw_producer_index) = 0;
  1868. }
  1869. void
  1870. bna_rit_create(struct bna_rx *rx)
  1871. {
  1872. struct list_head *qe_rxp;
  1873. struct bna_rxp *rxp;
  1874. struct bna_rxq *q0 = NULL;
  1875. struct bna_rxq *q1 = NULL;
  1876. int offset;
  1877. offset = 0;
  1878. list_for_each(qe_rxp, &rx->rxp_q) {
  1879. rxp = (struct bna_rxp *)qe_rxp;
  1880. GET_RXQS(rxp, q0, q1);
  1881. rx->rxf.rit_segment->rit[offset].large_rxq_id = q0->rxq_id;
  1882. rx->rxf.rit_segment->rit[offset].small_rxq_id =
  1883. (q1 ? q1->rxq_id : 0);
  1884. offset++;
  1885. }
  1886. }
  1887. static int
  1888. _rx_can_satisfy(struct bna_rx_mod *rx_mod,
  1889. struct bna_rx_config *rx_cfg)
  1890. {
  1891. if ((rx_mod->rx_free_count == 0) ||
  1892. (rx_mod->rxp_free_count == 0) ||
  1893. (rx_mod->rxq_free_count == 0))
  1894. return 0;
  1895. if (rx_cfg->rxp_type == BNA_RXP_SINGLE) {
  1896. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1897. (rx_mod->rxq_free_count < rx_cfg->num_paths))
  1898. return 0;
  1899. } else {
  1900. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1901. (rx_mod->rxq_free_count < (2 * rx_cfg->num_paths)))
  1902. return 0;
  1903. }
  1904. if (!bna_rit_mod_can_satisfy(&rx_mod->bna->rit_mod, rx_cfg->num_paths))
  1905. return 0;
  1906. return 1;
  1907. }
  1908. static struct bna_rxq *
  1909. _get_free_rxq(struct bna_rx_mod *rx_mod)
  1910. {
  1911. struct bna_rxq *rxq = NULL;
  1912. struct list_head *qe = NULL;
  1913. bfa_q_deq(&rx_mod->rxq_free_q, &qe);
  1914. if (qe) {
  1915. rx_mod->rxq_free_count--;
  1916. rxq = (struct bna_rxq *)qe;
  1917. }
  1918. return rxq;
  1919. }
  1920. static void
  1921. _put_free_rxq(struct bna_rx_mod *rx_mod, struct bna_rxq *rxq)
  1922. {
  1923. bfa_q_qe_init(&rxq->qe);
  1924. list_add_tail(&rxq->qe, &rx_mod->rxq_free_q);
  1925. rx_mod->rxq_free_count++;
  1926. }
  1927. static struct bna_rxp *
  1928. _get_free_rxp(struct bna_rx_mod *rx_mod)
  1929. {
  1930. struct list_head *qe = NULL;
  1931. struct bna_rxp *rxp = NULL;
  1932. bfa_q_deq(&rx_mod->rxp_free_q, &qe);
  1933. if (qe) {
  1934. rx_mod->rxp_free_count--;
  1935. rxp = (struct bna_rxp *)qe;
  1936. }
  1937. return rxp;
  1938. }
  1939. static void
  1940. _put_free_rxp(struct bna_rx_mod *rx_mod, struct bna_rxp *rxp)
  1941. {
  1942. bfa_q_qe_init(&rxp->qe);
  1943. list_add_tail(&rxp->qe, &rx_mod->rxp_free_q);
  1944. rx_mod->rxp_free_count++;
  1945. }
  1946. static struct bna_rx *
  1947. _get_free_rx(struct bna_rx_mod *rx_mod)
  1948. {
  1949. struct list_head *qe = NULL;
  1950. struct bna_rx *rx = NULL;
  1951. bfa_q_deq(&rx_mod->rx_free_q, &qe);
  1952. if (qe) {
  1953. rx_mod->rx_free_count--;
  1954. rx = (struct bna_rx *)qe;
  1955. bfa_q_qe_init(qe);
  1956. list_add_tail(&rx->qe, &rx_mod->rx_active_q);
  1957. }
  1958. return rx;
  1959. }
  1960. static void
  1961. _put_free_rx(struct bna_rx_mod *rx_mod, struct bna_rx *rx)
  1962. {
  1963. bfa_q_qe_init(&rx->qe);
  1964. list_add_tail(&rx->qe, &rx_mod->rx_free_q);
  1965. rx_mod->rx_free_count++;
  1966. }
  1967. static void
  1968. _rx_init(struct bna_rx *rx, struct bna *bna)
  1969. {
  1970. rx->bna = bna;
  1971. rx->rx_flags = 0;
  1972. INIT_LIST_HEAD(&rx->rxp_q);
  1973. rx->rxq_stop_wc.wc_resume = bna_rx_cb_rxq_stopped_all;
  1974. rx->rxq_stop_wc.wc_cbarg = rx;
  1975. rx->rxq_stop_wc.wc_count = 0;
  1976. rx->stop_cbfn = NULL;
  1977. rx->stop_cbarg = NULL;
  1978. }
  1979. static void
  1980. _rxp_add_rxqs(struct bna_rxp *rxp,
  1981. struct bna_rxq *q0,
  1982. struct bna_rxq *q1)
  1983. {
  1984. switch (rxp->type) {
  1985. case BNA_RXP_SINGLE:
  1986. rxp->rxq.single.only = q0;
  1987. rxp->rxq.single.reserved = NULL;
  1988. break;
  1989. case BNA_RXP_SLR:
  1990. rxp->rxq.slr.large = q0;
  1991. rxp->rxq.slr.small = q1;
  1992. break;
  1993. case BNA_RXP_HDS:
  1994. rxp->rxq.hds.data = q0;
  1995. rxp->rxq.hds.hdr = q1;
  1996. break;
  1997. default:
  1998. break;
  1999. }
  2000. }
  2001. static void
  2002. _rxq_qpt_init(struct bna_rxq *rxq,
  2003. struct bna_rxp *rxp,
  2004. u32 page_count,
  2005. u32 page_size,
  2006. struct bna_mem_descr *qpt_mem,
  2007. struct bna_mem_descr *swqpt_mem,
  2008. struct bna_mem_descr *page_mem)
  2009. {
  2010. int i;
  2011. rxq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  2012. rxq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  2013. rxq->qpt.kv_qpt_ptr = qpt_mem->kva;
  2014. rxq->qpt.page_count = page_count;
  2015. rxq->qpt.page_size = page_size;
  2016. rxq->rcb->sw_qpt = (void **) swqpt_mem->kva;
  2017. for (i = 0; i < rxq->qpt.page_count; i++) {
  2018. rxq->rcb->sw_qpt[i] = page_mem[i].kva;
  2019. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].lsb =
  2020. page_mem[i].dma.lsb;
  2021. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].msb =
  2022. page_mem[i].dma.msb;
  2023. }
  2024. }
  2025. static void
  2026. _rxp_cqpt_setup(struct bna_rxp *rxp,
  2027. u32 page_count,
  2028. u32 page_size,
  2029. struct bna_mem_descr *qpt_mem,
  2030. struct bna_mem_descr *swqpt_mem,
  2031. struct bna_mem_descr *page_mem)
  2032. {
  2033. int i;
  2034. rxp->cq.qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  2035. rxp->cq.qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  2036. rxp->cq.qpt.kv_qpt_ptr = qpt_mem->kva;
  2037. rxp->cq.qpt.page_count = page_count;
  2038. rxp->cq.qpt.page_size = page_size;
  2039. rxp->cq.ccb->sw_qpt = (void **) swqpt_mem->kva;
  2040. for (i = 0; i < rxp->cq.qpt.page_count; i++) {
  2041. rxp->cq.ccb->sw_qpt[i] = page_mem[i].kva;
  2042. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].lsb =
  2043. page_mem[i].dma.lsb;
  2044. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].msb =
  2045. page_mem[i].dma.msb;
  2046. }
  2047. }
  2048. static void
  2049. _rx_add_rxp(struct bna_rx *rx, struct bna_rxp *rxp)
  2050. {
  2051. list_add_tail(&rxp->qe, &rx->rxp_q);
  2052. }
  2053. static void
  2054. _init_rxmod_queues(struct bna_rx_mod *rx_mod)
  2055. {
  2056. INIT_LIST_HEAD(&rx_mod->rx_free_q);
  2057. INIT_LIST_HEAD(&rx_mod->rxq_free_q);
  2058. INIT_LIST_HEAD(&rx_mod->rxp_free_q);
  2059. INIT_LIST_HEAD(&rx_mod->rx_active_q);
  2060. rx_mod->rx_free_count = 0;
  2061. rx_mod->rxq_free_count = 0;
  2062. rx_mod->rxp_free_count = 0;
  2063. }
  2064. static void
  2065. _rx_ctor(struct bna_rx *rx, int id)
  2066. {
  2067. bfa_q_qe_init(&rx->qe);
  2068. INIT_LIST_HEAD(&rx->rxp_q);
  2069. rx->bna = NULL;
  2070. rx->rxf.rxf_id = id;
  2071. /* FIXME: mbox_qe ctor()?? */
  2072. bfa_q_qe_init(&rx->mbox_qe.qe);
  2073. rx->stop_cbfn = NULL;
  2074. rx->stop_cbarg = NULL;
  2075. }
  2076. void
  2077. bna_rx_cb_multi_rxq_stopped(void *arg, int status)
  2078. {
  2079. struct bna_rxp *rxp = (struct bna_rxp *)arg;
  2080. bfa_wc_down(&rxp->rx->rxq_stop_wc);
  2081. }
  2082. void
  2083. bna_rx_cb_rxq_stopped_all(void *arg)
  2084. {
  2085. struct bna_rx *rx = (struct bna_rx *)arg;
  2086. bfa_fsm_send_event(rx, RX_E_RXQ_STOPPED);
  2087. }
  2088. static void
  2089. bna_rx_mod_cb_rx_stopped(void *arg, struct bna_rx *rx,
  2090. enum bna_cb_status status)
  2091. {
  2092. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2093. bfa_wc_down(&rx_mod->rx_stop_wc);
  2094. }
  2095. static void
  2096. bna_rx_mod_cb_rx_stopped_all(void *arg)
  2097. {
  2098. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2099. if (rx_mod->stop_cbfn)
  2100. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2101. rx_mod->stop_cbfn = NULL;
  2102. }
  2103. static void
  2104. bna_rx_start(struct bna_rx *rx)
  2105. {
  2106. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2107. if (rx->rx_flags & BNA_RX_F_ENABLE)
  2108. bfa_fsm_send_event(rx, RX_E_START);
  2109. }
  2110. static void
  2111. bna_rx_stop(struct bna_rx *rx)
  2112. {
  2113. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2114. if (rx->fsm == (bfa_fsm_t) bna_rx_sm_stopped)
  2115. bna_rx_mod_cb_rx_stopped(&rx->bna->rx_mod, rx, BNA_CB_SUCCESS);
  2116. else {
  2117. rx->stop_cbfn = bna_rx_mod_cb_rx_stopped;
  2118. rx->stop_cbarg = &rx->bna->rx_mod;
  2119. bfa_fsm_send_event(rx, RX_E_STOP);
  2120. }
  2121. }
  2122. static void
  2123. bna_rx_fail(struct bna_rx *rx)
  2124. {
  2125. /* Indicate port is not enabled, and failed */
  2126. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2127. rx->rx_flags |= BNA_RX_F_PORT_FAILED;
  2128. bfa_fsm_send_event(rx, RX_E_FAIL);
  2129. }
  2130. void
  2131. bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2132. {
  2133. struct bna_rx *rx;
  2134. struct list_head *qe;
  2135. rx_mod->flags |= BNA_RX_MOD_F_PORT_STARTED;
  2136. if (type == BNA_RX_T_LOOPBACK)
  2137. rx_mod->flags |= BNA_RX_MOD_F_PORT_LOOPBACK;
  2138. list_for_each(qe, &rx_mod->rx_active_q) {
  2139. rx = (struct bna_rx *)qe;
  2140. if (rx->type == type)
  2141. bna_rx_start(rx);
  2142. }
  2143. }
  2144. void
  2145. bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2146. {
  2147. struct bna_rx *rx;
  2148. struct list_head *qe;
  2149. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2150. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2151. rx_mod->stop_cbfn = bna_port_cb_rx_stopped;
  2152. /**
  2153. * Before calling bna_rx_stop(), increment rx_stop_wc as many times
  2154. * as we are going to call bna_rx_stop
  2155. */
  2156. list_for_each(qe, &rx_mod->rx_active_q) {
  2157. rx = (struct bna_rx *)qe;
  2158. if (rx->type == type)
  2159. bfa_wc_up(&rx_mod->rx_stop_wc);
  2160. }
  2161. if (rx_mod->rx_stop_wc.wc_count == 0) {
  2162. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2163. rx_mod->stop_cbfn = NULL;
  2164. return;
  2165. }
  2166. list_for_each(qe, &rx_mod->rx_active_q) {
  2167. rx = (struct bna_rx *)qe;
  2168. if (rx->type == type)
  2169. bna_rx_stop(rx);
  2170. }
  2171. }
  2172. void
  2173. bna_rx_mod_fail(struct bna_rx_mod *rx_mod)
  2174. {
  2175. struct bna_rx *rx;
  2176. struct list_head *qe;
  2177. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2178. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2179. list_for_each(qe, &rx_mod->rx_active_q) {
  2180. rx = (struct bna_rx *)qe;
  2181. bna_rx_fail(rx);
  2182. }
  2183. }
  2184. void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
  2185. struct bna_res_info *res_info)
  2186. {
  2187. int index;
  2188. struct bna_rx *rx_ptr;
  2189. struct bna_rxp *rxp_ptr;
  2190. struct bna_rxq *rxq_ptr;
  2191. rx_mod->bna = bna;
  2192. rx_mod->flags = 0;
  2193. rx_mod->rx = (struct bna_rx *)
  2194. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.mdl[0].kva;
  2195. rx_mod->rxp = (struct bna_rxp *)
  2196. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mdl[0].kva;
  2197. rx_mod->rxq = (struct bna_rxq *)
  2198. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  2199. /* Initialize the queues */
  2200. _init_rxmod_queues(rx_mod);
  2201. /* Build RX queues */
  2202. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2203. rx_ptr = &rx_mod->rx[index];
  2204. _rx_ctor(rx_ptr, index);
  2205. list_add_tail(&rx_ptr->qe, &rx_mod->rx_free_q);
  2206. rx_mod->rx_free_count++;
  2207. }
  2208. /* build RX-path queue */
  2209. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2210. rxp_ptr = &rx_mod->rxp[index];
  2211. rxp_ptr->cq.cq_id = index;
  2212. bfa_q_qe_init(&rxp_ptr->qe);
  2213. list_add_tail(&rxp_ptr->qe, &rx_mod->rxp_free_q);
  2214. rx_mod->rxp_free_count++;
  2215. }
  2216. /* build RXQ queue */
  2217. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2218. rxq_ptr = &rx_mod->rxq[index];
  2219. rxq_ptr->rxq_id = index;
  2220. bfa_q_qe_init(&rxq_ptr->qe);
  2221. list_add_tail(&rxq_ptr->qe, &rx_mod->rxq_free_q);
  2222. rx_mod->rxq_free_count++;
  2223. }
  2224. rx_mod->rx_stop_wc.wc_resume = bna_rx_mod_cb_rx_stopped_all;
  2225. rx_mod->rx_stop_wc.wc_cbarg = rx_mod;
  2226. rx_mod->rx_stop_wc.wc_count = 0;
  2227. }
  2228. void
  2229. bna_rx_mod_uninit(struct bna_rx_mod *rx_mod)
  2230. {
  2231. struct list_head *qe;
  2232. int i;
  2233. i = 0;
  2234. list_for_each(qe, &rx_mod->rx_free_q)
  2235. i++;
  2236. i = 0;
  2237. list_for_each(qe, &rx_mod->rxp_free_q)
  2238. i++;
  2239. i = 0;
  2240. list_for_each(qe, &rx_mod->rxq_free_q)
  2241. i++;
  2242. rx_mod->bna = NULL;
  2243. }
  2244. int
  2245. bna_rx_state_get(struct bna_rx *rx)
  2246. {
  2247. return bfa_sm_to_state(rx_sm_table, rx->fsm);
  2248. }
  2249. void
  2250. bna_rx_res_req(struct bna_rx_config *q_cfg, struct bna_res_info *res_info)
  2251. {
  2252. u32 cq_size, hq_size, dq_size;
  2253. u32 cpage_count, hpage_count, dpage_count;
  2254. struct bna_mem_info *mem_info;
  2255. u32 cq_depth;
  2256. u32 hq_depth;
  2257. u32 dq_depth;
  2258. dq_depth = q_cfg->q_depth;
  2259. hq_depth = ((q_cfg->rxp_type == BNA_RXP_SINGLE) ? 0 : q_cfg->q_depth);
  2260. cq_depth = dq_depth + hq_depth;
  2261. BNA_TO_POWER_OF_2_HIGH(cq_depth);
  2262. cq_size = cq_depth * BFI_CQ_WI_SIZE;
  2263. cq_size = ALIGN(cq_size, PAGE_SIZE);
  2264. cpage_count = SIZE_TO_PAGES(cq_size);
  2265. BNA_TO_POWER_OF_2_HIGH(dq_depth);
  2266. dq_size = dq_depth * BFI_RXQ_WI_SIZE;
  2267. dq_size = ALIGN(dq_size, PAGE_SIZE);
  2268. dpage_count = SIZE_TO_PAGES(dq_size);
  2269. if (BNA_RXP_SINGLE != q_cfg->rxp_type) {
  2270. BNA_TO_POWER_OF_2_HIGH(hq_depth);
  2271. hq_size = hq_depth * BFI_RXQ_WI_SIZE;
  2272. hq_size = ALIGN(hq_size, PAGE_SIZE);
  2273. hpage_count = SIZE_TO_PAGES(hq_size);
  2274. } else {
  2275. hpage_count = 0;
  2276. }
  2277. /* CCB structures */
  2278. res_info[BNA_RX_RES_MEM_T_CCB].res_type = BNA_RES_T_MEM;
  2279. mem_info = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info;
  2280. mem_info->mem_type = BNA_MEM_T_KVA;
  2281. mem_info->len = sizeof(struct bna_ccb);
  2282. mem_info->num = q_cfg->num_paths;
  2283. /* RCB structures */
  2284. res_info[BNA_RX_RES_MEM_T_RCB].res_type = BNA_RES_T_MEM;
  2285. mem_info = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info;
  2286. mem_info->mem_type = BNA_MEM_T_KVA;
  2287. mem_info->len = sizeof(struct bna_rcb);
  2288. mem_info->num = BNA_GET_RXQS(q_cfg);
  2289. /* Completion QPT */
  2290. res_info[BNA_RX_RES_MEM_T_CQPT].res_type = BNA_RES_T_MEM;
  2291. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info;
  2292. mem_info->mem_type = BNA_MEM_T_DMA;
  2293. mem_info->len = cpage_count * sizeof(struct bna_dma_addr);
  2294. mem_info->num = q_cfg->num_paths;
  2295. /* Completion s/w QPT */
  2296. res_info[BNA_RX_RES_MEM_T_CSWQPT].res_type = BNA_RES_T_MEM;
  2297. mem_info = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info;
  2298. mem_info->mem_type = BNA_MEM_T_KVA;
  2299. mem_info->len = cpage_count * sizeof(void *);
  2300. mem_info->num = q_cfg->num_paths;
  2301. /* Completion QPT pages */
  2302. res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_type = BNA_RES_T_MEM;
  2303. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info;
  2304. mem_info->mem_type = BNA_MEM_T_DMA;
  2305. mem_info->len = PAGE_SIZE;
  2306. mem_info->num = cpage_count * q_cfg->num_paths;
  2307. /* Data QPTs */
  2308. res_info[BNA_RX_RES_MEM_T_DQPT].res_type = BNA_RES_T_MEM;
  2309. mem_info = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info;
  2310. mem_info->mem_type = BNA_MEM_T_DMA;
  2311. mem_info->len = dpage_count * sizeof(struct bna_dma_addr);
  2312. mem_info->num = q_cfg->num_paths;
  2313. /* Data s/w QPTs */
  2314. res_info[BNA_RX_RES_MEM_T_DSWQPT].res_type = BNA_RES_T_MEM;
  2315. mem_info = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info;
  2316. mem_info->mem_type = BNA_MEM_T_KVA;
  2317. mem_info->len = dpage_count * sizeof(void *);
  2318. mem_info->num = q_cfg->num_paths;
  2319. /* Data QPT pages */
  2320. res_info[BNA_RX_RES_MEM_T_DPAGE].res_type = BNA_RES_T_MEM;
  2321. mem_info = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info;
  2322. mem_info->mem_type = BNA_MEM_T_DMA;
  2323. mem_info->len = PAGE_SIZE;
  2324. mem_info->num = dpage_count * q_cfg->num_paths;
  2325. /* Hdr QPTs */
  2326. res_info[BNA_RX_RES_MEM_T_HQPT].res_type = BNA_RES_T_MEM;
  2327. mem_info = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info;
  2328. mem_info->mem_type = BNA_MEM_T_DMA;
  2329. mem_info->len = hpage_count * sizeof(struct bna_dma_addr);
  2330. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2331. /* Hdr s/w QPTs */
  2332. res_info[BNA_RX_RES_MEM_T_HSWQPT].res_type = BNA_RES_T_MEM;
  2333. mem_info = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info;
  2334. mem_info->mem_type = BNA_MEM_T_KVA;
  2335. mem_info->len = hpage_count * sizeof(void *);
  2336. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2337. /* Hdr QPT pages */
  2338. res_info[BNA_RX_RES_MEM_T_HPAGE].res_type = BNA_RES_T_MEM;
  2339. mem_info = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info;
  2340. mem_info->mem_type = BNA_MEM_T_DMA;
  2341. mem_info->len = (hpage_count ? PAGE_SIZE : 0);
  2342. mem_info->num = (hpage_count ? (hpage_count * q_cfg->num_paths) : 0);
  2343. /* RX Interrupts */
  2344. res_info[BNA_RX_RES_T_INTR].res_type = BNA_RES_T_INTR;
  2345. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.intr_type = BNA_INTR_T_MSIX;
  2346. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.num = q_cfg->num_paths;
  2347. }
  2348. struct bna_rx *
  2349. bna_rx_create(struct bna *bna, struct bnad *bnad,
  2350. struct bna_rx_config *rx_cfg,
  2351. struct bna_rx_event_cbfn *rx_cbfn,
  2352. struct bna_res_info *res_info,
  2353. void *priv)
  2354. {
  2355. struct bna_rx_mod *rx_mod = &bna->rx_mod;
  2356. struct bna_rx *rx;
  2357. struct bna_rxp *rxp;
  2358. struct bna_rxq *q0;
  2359. struct bna_rxq *q1;
  2360. struct bna_intr_info *intr_info;
  2361. u32 page_count;
  2362. struct bna_mem_descr *ccb_mem;
  2363. struct bna_mem_descr *rcb_mem;
  2364. struct bna_mem_descr *unmapq_mem;
  2365. struct bna_mem_descr *cqpt_mem;
  2366. struct bna_mem_descr *cswqpt_mem;
  2367. struct bna_mem_descr *cpage_mem;
  2368. struct bna_mem_descr *hqpt_mem; /* Header/Small Q qpt */
  2369. struct bna_mem_descr *dqpt_mem; /* Data/Large Q qpt */
  2370. struct bna_mem_descr *hsqpt_mem; /* s/w qpt for hdr */
  2371. struct bna_mem_descr *dsqpt_mem; /* s/w qpt for data */
  2372. struct bna_mem_descr *hpage_mem; /* hdr page mem */
  2373. struct bna_mem_descr *dpage_mem; /* data page mem */
  2374. int i, cpage_idx = 0, dpage_idx = 0, hpage_idx = 0;
  2375. int dpage_count, hpage_count, rcb_idx;
  2376. struct bna_ib_config ibcfg;
  2377. /* Fail if we don't have enough RXPs, RXQs */
  2378. if (!_rx_can_satisfy(rx_mod, rx_cfg))
  2379. return NULL;
  2380. /* Initialize resource pointers */
  2381. intr_info = &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
  2382. ccb_mem = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info.mdl[0];
  2383. rcb_mem = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info.mdl[0];
  2384. unmapq_mem = &res_info[BNA_RX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[0];
  2385. cqpt_mem = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info.mdl[0];
  2386. cswqpt_mem = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info.mdl[0];
  2387. cpage_mem = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.mdl[0];
  2388. hqpt_mem = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info.mdl[0];
  2389. dqpt_mem = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info.mdl[0];
  2390. hsqpt_mem = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info.mdl[0];
  2391. dsqpt_mem = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info.mdl[0];
  2392. hpage_mem = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.mdl[0];
  2393. dpage_mem = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.mdl[0];
  2394. /* Compute q depth & page count */
  2395. page_count = res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.num /
  2396. rx_cfg->num_paths;
  2397. dpage_count = res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.num /
  2398. rx_cfg->num_paths;
  2399. hpage_count = res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.num /
  2400. rx_cfg->num_paths;
  2401. /* Get RX pointer */
  2402. rx = _get_free_rx(rx_mod);
  2403. _rx_init(rx, bna);
  2404. rx->priv = priv;
  2405. rx->type = rx_cfg->rx_type;
  2406. rx->rcb_setup_cbfn = rx_cbfn->rcb_setup_cbfn;
  2407. rx->rcb_destroy_cbfn = rx_cbfn->rcb_destroy_cbfn;
  2408. rx->ccb_setup_cbfn = rx_cbfn->ccb_setup_cbfn;
  2409. rx->ccb_destroy_cbfn = rx_cbfn->ccb_destroy_cbfn;
  2410. /* Following callbacks are mandatory */
  2411. rx->rx_cleanup_cbfn = rx_cbfn->rx_cleanup_cbfn;
  2412. rx->rx_post_cbfn = rx_cbfn->rx_post_cbfn;
  2413. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_STARTED) {
  2414. switch (rx->type) {
  2415. case BNA_RX_T_REGULAR:
  2416. if (!(rx->bna->rx_mod.flags &
  2417. BNA_RX_MOD_F_PORT_LOOPBACK))
  2418. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2419. break;
  2420. case BNA_RX_T_LOOPBACK:
  2421. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_LOOPBACK)
  2422. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2423. break;
  2424. }
  2425. }
  2426. for (i = 0, rcb_idx = 0; i < rx_cfg->num_paths; i++) {
  2427. rxp = _get_free_rxp(rx_mod);
  2428. rxp->type = rx_cfg->rxp_type;
  2429. rxp->rx = rx;
  2430. rxp->cq.rx = rx;
  2431. /* Get required RXQs, and queue them to rx-path */
  2432. q0 = _get_free_rxq(rx_mod);
  2433. if (BNA_RXP_SINGLE == rx_cfg->rxp_type)
  2434. q1 = NULL;
  2435. else
  2436. q1 = _get_free_rxq(rx_mod);
  2437. /* Initialize IB */
  2438. if (1 == intr_info->num) {
  2439. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2440. intr_info->intr_type,
  2441. intr_info->idl[0].vector);
  2442. rxp->vector = intr_info->idl[0].vector;
  2443. } else {
  2444. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2445. intr_info->intr_type,
  2446. intr_info->idl[i].vector);
  2447. /* Map the MSI-x vector used for this RXP */
  2448. rxp->vector = intr_info->idl[i].vector;
  2449. }
  2450. rxp->cq.ib_seg_offset = bna_ib_reserve_idx(rxp->cq.ib);
  2451. ibcfg.coalescing_timeo = BFI_RX_COALESCING_TIMEO;
  2452. ibcfg.interpkt_count = BFI_RX_INTERPKT_COUNT;
  2453. ibcfg.interpkt_timeo = BFI_RX_INTERPKT_TIMEO;
  2454. ibcfg.ctrl_flags = BFI_IB_CF_INT_ENABLE;
  2455. bna_ib_config(rxp->cq.ib, &ibcfg);
  2456. /* Link rxqs to rxp */
  2457. _rxp_add_rxqs(rxp, q0, q1);
  2458. /* Link rxp to rx */
  2459. _rx_add_rxp(rx, rxp);
  2460. q0->rx = rx;
  2461. q0->rxp = rxp;
  2462. /* Initialize RCB for the large / data q */
  2463. q0->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2464. RXQ_RCB_INIT(q0, rxp, rx_cfg->q_depth, bna, 0,
  2465. (void *)unmapq_mem[rcb_idx].kva);
  2466. rcb_idx++;
  2467. (q0)->rx_packets = (q0)->rx_bytes = 0;
  2468. (q0)->rx_packets_with_error = (q0)->rxbuf_alloc_failed = 0;
  2469. /* Initialize RXQs */
  2470. _rxq_qpt_init(q0, rxp, dpage_count, PAGE_SIZE,
  2471. &dqpt_mem[i], &dsqpt_mem[i], &dpage_mem[dpage_idx]);
  2472. q0->rcb->page_idx = dpage_idx;
  2473. q0->rcb->page_count = dpage_count;
  2474. dpage_idx += dpage_count;
  2475. /* Call bnad to complete rcb setup */
  2476. if (rx->rcb_setup_cbfn)
  2477. rx->rcb_setup_cbfn(bnad, q0->rcb);
  2478. if (q1) {
  2479. q1->rx = rx;
  2480. q1->rxp = rxp;
  2481. q1->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2482. RXQ_RCB_INIT(q1, rxp, rx_cfg->q_depth, bna, 1,
  2483. (void *)unmapq_mem[rcb_idx].kva);
  2484. rcb_idx++;
  2485. (q1)->buffer_size = (rx_cfg)->small_buff_size;
  2486. (q1)->rx_packets = (q1)->rx_bytes = 0;
  2487. (q1)->rx_packets_with_error =
  2488. (q1)->rxbuf_alloc_failed = 0;
  2489. _rxq_qpt_init(q1, rxp, hpage_count, PAGE_SIZE,
  2490. &hqpt_mem[i], &hsqpt_mem[i],
  2491. &hpage_mem[hpage_idx]);
  2492. q1->rcb->page_idx = hpage_idx;
  2493. q1->rcb->page_count = hpage_count;
  2494. hpage_idx += hpage_count;
  2495. /* Call bnad to complete rcb setup */
  2496. if (rx->rcb_setup_cbfn)
  2497. rx->rcb_setup_cbfn(bnad, q1->rcb);
  2498. }
  2499. /* Setup RXP::CQ */
  2500. rxp->cq.ccb = (struct bna_ccb *) ccb_mem[i].kva;
  2501. _rxp_cqpt_setup(rxp, page_count, PAGE_SIZE,
  2502. &cqpt_mem[i], &cswqpt_mem[i], &cpage_mem[cpage_idx]);
  2503. rxp->cq.ccb->page_idx = cpage_idx;
  2504. rxp->cq.ccb->page_count = page_count;
  2505. cpage_idx += page_count;
  2506. rxp->cq.ccb->pkt_rate.small_pkt_cnt = 0;
  2507. rxp->cq.ccb->pkt_rate.large_pkt_cnt = 0;
  2508. rxp->cq.ccb->producer_index = 0;
  2509. rxp->cq.ccb->q_depth = rx_cfg->q_depth +
  2510. ((rx_cfg->rxp_type == BNA_RXP_SINGLE) ?
  2511. 0 : rx_cfg->q_depth);
  2512. rxp->cq.ccb->i_dbell = &rxp->cq.ib->door_bell;
  2513. rxp->cq.ccb->rcb[0] = q0->rcb;
  2514. if (q1)
  2515. rxp->cq.ccb->rcb[1] = q1->rcb;
  2516. rxp->cq.ccb->cq = &rxp->cq;
  2517. rxp->cq.ccb->bnad = bna->bnad;
  2518. rxp->cq.ccb->hw_producer_index =
  2519. ((volatile u32 *)rxp->cq.ib->ib_seg_host_addr_kva +
  2520. (rxp->cq.ib_seg_offset * BFI_IBIDX_SIZE));
  2521. *(rxp->cq.ccb->hw_producer_index) = 0;
  2522. rxp->cq.ccb->intr_type = intr_info->intr_type;
  2523. rxp->cq.ccb->intr_vector = (intr_info->num == 1) ?
  2524. intr_info->idl[0].vector :
  2525. intr_info->idl[i].vector;
  2526. rxp->cq.ccb->rx_coalescing_timeo =
  2527. rxp->cq.ib->ib_config.coalescing_timeo;
  2528. rxp->cq.ccb->id = i;
  2529. /* Call bnad to complete CCB setup */
  2530. if (rx->ccb_setup_cbfn)
  2531. rx->ccb_setup_cbfn(bnad, rxp->cq.ccb);
  2532. } /* for each rx-path */
  2533. bna_rxf_init(&rx->rxf, rx, rx_cfg);
  2534. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  2535. return rx;
  2536. }
  2537. void
  2538. bna_rx_destroy(struct bna_rx *rx)
  2539. {
  2540. struct bna_rx_mod *rx_mod = &rx->bna->rx_mod;
  2541. struct bna_ib_mod *ib_mod = &rx->bna->ib_mod;
  2542. struct bna_rxq *q0 = NULL;
  2543. struct bna_rxq *q1 = NULL;
  2544. struct bna_rxp *rxp;
  2545. struct list_head *qe;
  2546. bna_rxf_uninit(&rx->rxf);
  2547. while (!list_empty(&rx->rxp_q)) {
  2548. bfa_q_deq(&rx->rxp_q, &rxp);
  2549. GET_RXQS(rxp, q0, q1);
  2550. /* Callback to bnad for destroying RCB */
  2551. if (rx->rcb_destroy_cbfn)
  2552. rx->rcb_destroy_cbfn(rx->bna->bnad, q0->rcb);
  2553. q0->rcb = NULL;
  2554. q0->rxp = NULL;
  2555. q0->rx = NULL;
  2556. _put_free_rxq(rx_mod, q0);
  2557. if (q1) {
  2558. /* Callback to bnad for destroying RCB */
  2559. if (rx->rcb_destroy_cbfn)
  2560. rx->rcb_destroy_cbfn(rx->bna->bnad, q1->rcb);
  2561. q1->rcb = NULL;
  2562. q1->rxp = NULL;
  2563. q1->rx = NULL;
  2564. _put_free_rxq(rx_mod, q1);
  2565. }
  2566. rxp->rxq.slr.large = NULL;
  2567. rxp->rxq.slr.small = NULL;
  2568. if (rxp->cq.ib) {
  2569. if (rxp->cq.ib_seg_offset != 0xff)
  2570. bna_ib_release_idx(rxp->cq.ib,
  2571. rxp->cq.ib_seg_offset);
  2572. bna_ib_put(ib_mod, rxp->cq.ib);
  2573. rxp->cq.ib = NULL;
  2574. }
  2575. /* Callback to bnad for destroying CCB */
  2576. if (rx->ccb_destroy_cbfn)
  2577. rx->ccb_destroy_cbfn(rx->bna->bnad, rxp->cq.ccb);
  2578. rxp->cq.ccb = NULL;
  2579. rxp->rx = NULL;
  2580. _put_free_rxp(rx_mod, rxp);
  2581. }
  2582. list_for_each(qe, &rx_mod->rx_active_q) {
  2583. if (qe == &rx->qe) {
  2584. list_del(&rx->qe);
  2585. bfa_q_qe_init(&rx->qe);
  2586. break;
  2587. }
  2588. }
  2589. rx->bna = NULL;
  2590. rx->priv = NULL;
  2591. _put_free_rx(rx_mod, rx);
  2592. }
  2593. void
  2594. bna_rx_enable(struct bna_rx *rx)
  2595. {
  2596. if (rx->fsm != (bfa_sm_t)bna_rx_sm_stopped)
  2597. return;
  2598. rx->rx_flags |= BNA_RX_F_ENABLE;
  2599. if (rx->rx_flags & BNA_RX_F_PORT_ENABLED)
  2600. bfa_fsm_send_event(rx, RX_E_START);
  2601. }
  2602. void
  2603. bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
  2604. void (*cbfn)(void *, struct bna_rx *,
  2605. enum bna_cb_status))
  2606. {
  2607. if (type == BNA_SOFT_CLEANUP) {
  2608. /* h/w should not be accessed. Treat we're stopped */
  2609. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  2610. } else {
  2611. rx->stop_cbfn = cbfn;
  2612. rx->stop_cbarg = rx->bna->bnad;
  2613. rx->rx_flags &= ~BNA_RX_F_ENABLE;
  2614. bfa_fsm_send_event(rx, RX_E_STOP);
  2615. }
  2616. }
  2617. /**
  2618. * TX
  2619. */
  2620. #define call_tx_stop_cbfn(tx, status)\
  2621. do {\
  2622. if ((tx)->stop_cbfn)\
  2623. (tx)->stop_cbfn((tx)->stop_cbarg, (tx), status);\
  2624. (tx)->stop_cbfn = NULL;\
  2625. (tx)->stop_cbarg = NULL;\
  2626. } while (0)
  2627. #define call_tx_prio_change_cbfn(tx, status)\
  2628. do {\
  2629. if ((tx)->prio_change_cbfn)\
  2630. (tx)->prio_change_cbfn((tx)->bna->bnad, (tx), status);\
  2631. (tx)->prio_change_cbfn = NULL;\
  2632. } while (0)
  2633. static void bna_tx_mod_cb_tx_stopped(void *tx_mod, struct bna_tx *tx,
  2634. enum bna_cb_status status);
  2635. static void bna_tx_cb_txq_stopped(void *arg, int status);
  2636. static void bna_tx_cb_stats_cleared(void *arg, int status);
  2637. static void __bna_tx_stop(struct bna_tx *tx);
  2638. static void __bna_tx_start(struct bna_tx *tx);
  2639. static void __bna_txf_stat_clr(struct bna_tx *tx);
  2640. enum bna_tx_event {
  2641. TX_E_START = 1,
  2642. TX_E_STOP = 2,
  2643. TX_E_FAIL = 3,
  2644. TX_E_TXQ_STOPPED = 4,
  2645. TX_E_PRIO_CHANGE = 5,
  2646. TX_E_STAT_CLEARED = 6,
  2647. };
  2648. enum bna_tx_state {
  2649. BNA_TX_STOPPED = 1,
  2650. BNA_TX_STARTED = 2,
  2651. BNA_TX_TXQ_STOP_WAIT = 3,
  2652. BNA_TX_PRIO_STOP_WAIT = 4,
  2653. BNA_TX_STAT_CLR_WAIT = 5,
  2654. };
  2655. bfa_fsm_state_decl(bna_tx, stopped, struct bna_tx,
  2656. enum bna_tx_event);
  2657. bfa_fsm_state_decl(bna_tx, started, struct bna_tx,
  2658. enum bna_tx_event);
  2659. bfa_fsm_state_decl(bna_tx, txq_stop_wait, struct bna_tx,
  2660. enum bna_tx_event);
  2661. bfa_fsm_state_decl(bna_tx, prio_stop_wait, struct bna_tx,
  2662. enum bna_tx_event);
  2663. bfa_fsm_state_decl(bna_tx, stat_clr_wait, struct bna_tx,
  2664. enum bna_tx_event);
  2665. static struct bfa_sm_table tx_sm_table[] = {
  2666. {BFA_SM(bna_tx_sm_stopped), BNA_TX_STOPPED},
  2667. {BFA_SM(bna_tx_sm_started), BNA_TX_STARTED},
  2668. {BFA_SM(bna_tx_sm_txq_stop_wait), BNA_TX_TXQ_STOP_WAIT},
  2669. {BFA_SM(bna_tx_sm_prio_stop_wait), BNA_TX_PRIO_STOP_WAIT},
  2670. {BFA_SM(bna_tx_sm_stat_clr_wait), BNA_TX_STAT_CLR_WAIT},
  2671. };
  2672. static void
  2673. bna_tx_sm_stopped_entry(struct bna_tx *tx)
  2674. {
  2675. struct bna_txq *txq;
  2676. struct list_head *qe;
  2677. list_for_each(qe, &tx->txq_q) {
  2678. txq = (struct bna_txq *)qe;
  2679. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2680. }
  2681. call_tx_stop_cbfn(tx, BNA_CB_SUCCESS);
  2682. }
  2683. static void
  2684. bna_tx_sm_stopped(struct bna_tx *tx, enum bna_tx_event event)
  2685. {
  2686. switch (event) {
  2687. case TX_E_START:
  2688. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2689. break;
  2690. case TX_E_STOP:
  2691. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2692. break;
  2693. case TX_E_FAIL:
  2694. /* No-op */
  2695. break;
  2696. case TX_E_PRIO_CHANGE:
  2697. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2698. break;
  2699. case TX_E_TXQ_STOPPED:
  2700. /**
  2701. * This event is received due to flushing of mbox when
  2702. * device fails
  2703. */
  2704. /* No-op */
  2705. break;
  2706. default:
  2707. bfa_sm_fault(tx->bna, event);
  2708. }
  2709. }
  2710. static void
  2711. bna_tx_sm_started_entry(struct bna_tx *tx)
  2712. {
  2713. struct bna_txq *txq;
  2714. struct list_head *qe;
  2715. __bna_tx_start(tx);
  2716. /* Start IB */
  2717. list_for_each(qe, &tx->txq_q) {
  2718. txq = (struct bna_txq *)qe;
  2719. bna_ib_ack(&txq->ib->door_bell, 0);
  2720. }
  2721. }
  2722. static void
  2723. bna_tx_sm_started(struct bna_tx *tx, enum bna_tx_event event)
  2724. {
  2725. struct bna_txq *txq;
  2726. struct list_head *qe;
  2727. switch (event) {
  2728. case TX_E_STOP:
  2729. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2730. __bna_tx_stop(tx);
  2731. break;
  2732. case TX_E_FAIL:
  2733. list_for_each(qe, &tx->txq_q) {
  2734. txq = (struct bna_txq *)qe;
  2735. bna_ib_fail(txq->ib);
  2736. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  2737. }
  2738. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2739. break;
  2740. case TX_E_PRIO_CHANGE:
  2741. bfa_fsm_set_state(tx, bna_tx_sm_prio_stop_wait);
  2742. break;
  2743. default:
  2744. bfa_sm_fault(tx->bna, event);
  2745. }
  2746. }
  2747. static void
  2748. bna_tx_sm_txq_stop_wait_entry(struct bna_tx *tx)
  2749. {
  2750. }
  2751. static void
  2752. bna_tx_sm_txq_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2753. {
  2754. struct bna_txq *txq;
  2755. struct list_head *qe;
  2756. switch (event) {
  2757. case TX_E_FAIL:
  2758. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2759. break;
  2760. case TX_E_TXQ_STOPPED:
  2761. list_for_each(qe, &tx->txq_q) {
  2762. txq = (struct bna_txq *)qe;
  2763. bna_ib_stop(txq->ib);
  2764. }
  2765. bfa_fsm_set_state(tx, bna_tx_sm_stat_clr_wait);
  2766. break;
  2767. case TX_E_PRIO_CHANGE:
  2768. /* No-op */
  2769. break;
  2770. default:
  2771. bfa_sm_fault(tx->bna, event);
  2772. }
  2773. }
  2774. static void
  2775. bna_tx_sm_prio_stop_wait_entry(struct bna_tx *tx)
  2776. {
  2777. __bna_tx_stop(tx);
  2778. }
  2779. static void
  2780. bna_tx_sm_prio_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2781. {
  2782. struct bna_txq *txq;
  2783. struct list_head *qe;
  2784. switch (event) {
  2785. case TX_E_STOP:
  2786. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2787. break;
  2788. case TX_E_FAIL:
  2789. call_tx_prio_change_cbfn(tx, BNA_CB_FAIL);
  2790. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2791. break;
  2792. case TX_E_TXQ_STOPPED:
  2793. list_for_each(qe, &tx->txq_q) {
  2794. txq = (struct bna_txq *)qe;
  2795. bna_ib_stop(txq->ib);
  2796. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2797. }
  2798. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2799. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2800. break;
  2801. case TX_E_PRIO_CHANGE:
  2802. /* No-op */
  2803. break;
  2804. default:
  2805. bfa_sm_fault(tx->bna, event);
  2806. }
  2807. }
  2808. static void
  2809. bna_tx_sm_stat_clr_wait_entry(struct bna_tx *tx)
  2810. {
  2811. __bna_txf_stat_clr(tx);
  2812. }
  2813. static void
  2814. bna_tx_sm_stat_clr_wait(struct bna_tx *tx, enum bna_tx_event event)
  2815. {
  2816. switch (event) {
  2817. case TX_E_FAIL:
  2818. case TX_E_STAT_CLEARED:
  2819. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2820. break;
  2821. default:
  2822. bfa_sm_fault(tx->bna, event);
  2823. }
  2824. }
  2825. static void
  2826. __bna_txq_start(struct bna_tx *tx, struct bna_txq *txq)
  2827. {
  2828. struct bna_rxtx_q_mem *q_mem;
  2829. struct bna_txq_mem txq_cfg;
  2830. struct bna_txq_mem *txq_mem;
  2831. struct bna_dma_addr cur_q_addr;
  2832. u32 pg_num;
  2833. void __iomem *base_addr;
  2834. unsigned long off;
  2835. /* Fill out structure, to be subsequently written to hardware */
  2836. txq_cfg.pg_tbl_addr_lo = txq->qpt.hw_qpt_ptr.lsb;
  2837. txq_cfg.pg_tbl_addr_hi = txq->qpt.hw_qpt_ptr.msb;
  2838. cur_q_addr = *((struct bna_dma_addr *)(txq->qpt.kv_qpt_ptr));
  2839. txq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  2840. txq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  2841. txq_cfg.pg_cnt_n_prd_ptr = (txq->qpt.page_count << 16) | 0x0;
  2842. txq_cfg.entry_n_pg_size = ((u32)(BFI_TXQ_WI_SIZE >> 2) << 16) |
  2843. (txq->qpt.page_size >> 2);
  2844. txq_cfg.int_blk_n_cns_ptr = ((((u32)txq->ib_seg_offset) << 24) |
  2845. ((u32)(txq->ib->ib_id & 0xff) << 16) | 0x0);
  2846. txq_cfg.cns_ptr2_n_q_state = BNA_Q_IDLE_STATE;
  2847. txq_cfg.nxt_qid_n_fid_n_pri = (((tx->txf.txf_id & 0x3f) << 3) |
  2848. (txq->priority & 0x7));
  2849. txq_cfg.wvc_n_cquota_n_rquota =
  2850. ((((u32)BFI_TX_MAX_WRR_QUOTA & 0xfff) << 12) |
  2851. (BFI_TX_MAX_WRR_QUOTA & 0xfff));
  2852. /* Setup the page and write to H/W */
  2853. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + tx->bna->port_num,
  2854. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2855. writel(pg_num, tx->bna->regs.page_addr);
  2856. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2857. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2858. q_mem = (struct bna_rxtx_q_mem *)0;
  2859. txq_mem = &q_mem[txq->txq_id].txq;
  2860. /*
  2861. * The following 4 lines, is a hack b'cos the H/W needs to read
  2862. * these DMA addresses as little endian
  2863. */
  2864. off = (unsigned long)&txq_mem->pg_tbl_addr_lo;
  2865. writel(htonl(txq_cfg.pg_tbl_addr_lo), base_addr + off);
  2866. off = (unsigned long)&txq_mem->pg_tbl_addr_hi;
  2867. writel(htonl(txq_cfg.pg_tbl_addr_hi), base_addr + off);
  2868. off = (unsigned long)&txq_mem->cur_q_entry_lo;
  2869. writel(htonl(txq_cfg.cur_q_entry_lo), base_addr + off);
  2870. off = (unsigned long)&txq_mem->cur_q_entry_hi;
  2871. writel(htonl(txq_cfg.cur_q_entry_hi), base_addr + off);
  2872. off = (unsigned long)&txq_mem->pg_cnt_n_prd_ptr;
  2873. writel(txq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  2874. off = (unsigned long)&txq_mem->entry_n_pg_size;
  2875. writel(txq_cfg.entry_n_pg_size, base_addr + off);
  2876. off = (unsigned long)&txq_mem->int_blk_n_cns_ptr;
  2877. writel(txq_cfg.int_blk_n_cns_ptr, base_addr + off);
  2878. off = (unsigned long)&txq_mem->cns_ptr2_n_q_state;
  2879. writel(txq_cfg.cns_ptr2_n_q_state, base_addr + off);
  2880. off = (unsigned long)&txq_mem->nxt_qid_n_fid_n_pri;
  2881. writel(txq_cfg.nxt_qid_n_fid_n_pri, base_addr + off);
  2882. off = (unsigned long)&txq_mem->wvc_n_cquota_n_rquota;
  2883. writel(txq_cfg.wvc_n_cquota_n_rquota, base_addr + off);
  2884. txq->tcb->producer_index = 0;
  2885. txq->tcb->consumer_index = 0;
  2886. *(txq->tcb->hw_consumer_index) = 0;
  2887. }
  2888. static void
  2889. __bna_txq_stop(struct bna_tx *tx, struct bna_txq *txq)
  2890. {
  2891. struct bfi_ll_q_stop_req ll_req;
  2892. u32 bit_mask[2] = {0, 0};
  2893. if (txq->txq_id < 32)
  2894. bit_mask[0] = (u32)1 << txq->txq_id;
  2895. else
  2896. bit_mask[1] = (u32)1 << (txq->txq_id - 32);
  2897. memset(&ll_req, 0, sizeof(ll_req));
  2898. ll_req.mh.msg_class = BFI_MC_LL;
  2899. ll_req.mh.msg_id = BFI_LL_H2I_TXQ_STOP_REQ;
  2900. ll_req.mh.mtag.h2i.lpu_id = 0;
  2901. ll_req.q_id_mask[0] = htonl(bit_mask[0]);
  2902. ll_req.q_id_mask[1] = htonl(bit_mask[1]);
  2903. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2904. bna_tx_cb_txq_stopped, tx);
  2905. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2906. }
  2907. static void
  2908. __bna_txf_start(struct bna_tx *tx)
  2909. {
  2910. struct bna_tx_fndb_ram *tx_fndb;
  2911. struct bna_txf *txf = &tx->txf;
  2912. void __iomem *base_addr;
  2913. unsigned long off;
  2914. writel(BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2915. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET),
  2916. tx->bna->regs.page_addr);
  2917. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2918. TX_FNDB_RAM_BASE_OFFSET);
  2919. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2920. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2921. writel(((u32)txf->vlan << 16) | txf->ctrl_flags,
  2922. base_addr + off);
  2923. if (tx->txf.txf_id < 32)
  2924. tx->bna->tx_mod.txf_bmap[0] |= ((u32)1 << tx->txf.txf_id);
  2925. else
  2926. tx->bna->tx_mod.txf_bmap[1] |= ((u32)
  2927. 1 << (tx->txf.txf_id - 32));
  2928. }
  2929. static void
  2930. __bna_txf_stop(struct bna_tx *tx)
  2931. {
  2932. struct bna_tx_fndb_ram *tx_fndb;
  2933. u32 page_num;
  2934. u32 ctl_flags;
  2935. struct bna_txf *txf = &tx->txf;
  2936. void __iomem *base_addr;
  2937. unsigned long off;
  2938. /* retrieve the running txf_flags & turn off enable bit */
  2939. page_num = BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2940. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET);
  2941. writel(page_num, tx->bna->regs.page_addr);
  2942. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2943. TX_FNDB_RAM_BASE_OFFSET);
  2944. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2945. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2946. ctl_flags = readl(base_addr + off);
  2947. ctl_flags &= ~BFI_TXF_CF_ENABLE;
  2948. writel(ctl_flags, base_addr + off);
  2949. if (tx->txf.txf_id < 32)
  2950. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)1 << tx->txf.txf_id);
  2951. else
  2952. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)
  2953. 1 << (tx->txf.txf_id - 32));
  2954. }
  2955. static void
  2956. __bna_txf_stat_clr(struct bna_tx *tx)
  2957. {
  2958. struct bfi_ll_stats_req ll_req;
  2959. u32 txf_bmap[2] = {0, 0};
  2960. if (tx->txf.txf_id < 32)
  2961. txf_bmap[0] = ((u32)1 << tx->txf.txf_id);
  2962. else
  2963. txf_bmap[1] = ((u32)1 << (tx->txf.txf_id - 32));
  2964. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_CLEAR_REQ, 0);
  2965. ll_req.stats_mask = 0;
  2966. ll_req.rxf_id_mask[0] = 0;
  2967. ll_req.rxf_id_mask[1] = 0;
  2968. ll_req.txf_id_mask[0] = htonl(txf_bmap[0]);
  2969. ll_req.txf_id_mask[1] = htonl(txf_bmap[1]);
  2970. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2971. bna_tx_cb_stats_cleared, tx);
  2972. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2973. }
  2974. static void
  2975. __bna_tx_start(struct bna_tx *tx)
  2976. {
  2977. struct bna_txq *txq;
  2978. struct list_head *qe;
  2979. list_for_each(qe, &tx->txq_q) {
  2980. txq = (struct bna_txq *)qe;
  2981. bna_ib_start(txq->ib);
  2982. __bna_txq_start(tx, txq);
  2983. }
  2984. __bna_txf_start(tx);
  2985. list_for_each(qe, &tx->txq_q) {
  2986. txq = (struct bna_txq *)qe;
  2987. txq->tcb->priority = txq->priority;
  2988. (tx->tx_resume_cbfn)(tx->bna->bnad, txq->tcb);
  2989. }
  2990. }
  2991. static void
  2992. __bna_tx_stop(struct bna_tx *tx)
  2993. {
  2994. struct bna_txq *txq;
  2995. struct list_head *qe;
  2996. list_for_each(qe, &tx->txq_q) {
  2997. txq = (struct bna_txq *)qe;
  2998. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  2999. }
  3000. __bna_txf_stop(tx);
  3001. list_for_each(qe, &tx->txq_q) {
  3002. txq = (struct bna_txq *)qe;
  3003. bfa_wc_up(&tx->txq_stop_wc);
  3004. }
  3005. list_for_each(qe, &tx->txq_q) {
  3006. txq = (struct bna_txq *)qe;
  3007. __bna_txq_stop(tx, txq);
  3008. }
  3009. }
  3010. static void
  3011. bna_txq_qpt_setup(struct bna_txq *txq, int page_count, int page_size,
  3012. struct bna_mem_descr *qpt_mem,
  3013. struct bna_mem_descr *swqpt_mem,
  3014. struct bna_mem_descr *page_mem)
  3015. {
  3016. int i;
  3017. txq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  3018. txq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  3019. txq->qpt.kv_qpt_ptr = qpt_mem->kva;
  3020. txq->qpt.page_count = page_count;
  3021. txq->qpt.page_size = page_size;
  3022. txq->tcb->sw_qpt = (void **) swqpt_mem->kva;
  3023. for (i = 0; i < page_count; i++) {
  3024. txq->tcb->sw_qpt[i] = page_mem[i].kva;
  3025. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].lsb =
  3026. page_mem[i].dma.lsb;
  3027. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].msb =
  3028. page_mem[i].dma.msb;
  3029. }
  3030. }
  3031. static void
  3032. bna_tx_free(struct bna_tx *tx)
  3033. {
  3034. struct bna_tx_mod *tx_mod = &tx->bna->tx_mod;
  3035. struct bna_txq *txq;
  3036. struct bna_ib_mod *ib_mod = &tx->bna->ib_mod;
  3037. struct list_head *qe;
  3038. while (!list_empty(&tx->txq_q)) {
  3039. bfa_q_deq(&tx->txq_q, &txq);
  3040. bfa_q_qe_init(&txq->qe);
  3041. if (txq->ib) {
  3042. if (txq->ib_seg_offset != -1)
  3043. bna_ib_release_idx(txq->ib,
  3044. txq->ib_seg_offset);
  3045. bna_ib_put(ib_mod, txq->ib);
  3046. txq->ib = NULL;
  3047. }
  3048. txq->tcb = NULL;
  3049. txq->tx = NULL;
  3050. list_add_tail(&txq->qe, &tx_mod->txq_free_q);
  3051. }
  3052. list_for_each(qe, &tx_mod->tx_active_q) {
  3053. if (qe == &tx->qe) {
  3054. list_del(&tx->qe);
  3055. bfa_q_qe_init(&tx->qe);
  3056. break;
  3057. }
  3058. }
  3059. tx->bna = NULL;
  3060. tx->priv = NULL;
  3061. list_add_tail(&tx->qe, &tx_mod->tx_free_q);
  3062. }
  3063. static void
  3064. bna_tx_cb_txq_stopped(void *arg, int status)
  3065. {
  3066. struct bna_tx *tx = (struct bna_tx *)arg;
  3067. bfa_q_qe_init(&tx->mbox_qe.qe);
  3068. bfa_wc_down(&tx->txq_stop_wc);
  3069. }
  3070. static void
  3071. bna_tx_cb_txq_stopped_all(void *arg)
  3072. {
  3073. struct bna_tx *tx = (struct bna_tx *)arg;
  3074. bfa_fsm_send_event(tx, TX_E_TXQ_STOPPED);
  3075. }
  3076. static void
  3077. bna_tx_cb_stats_cleared(void *arg, int status)
  3078. {
  3079. struct bna_tx *tx = (struct bna_tx *)arg;
  3080. bfa_q_qe_init(&tx->mbox_qe.qe);
  3081. bfa_fsm_send_event(tx, TX_E_STAT_CLEARED);
  3082. }
  3083. static void
  3084. bna_tx_start(struct bna_tx *tx)
  3085. {
  3086. tx->flags |= BNA_TX_F_PORT_STARTED;
  3087. if (tx->flags & BNA_TX_F_ENABLED)
  3088. bfa_fsm_send_event(tx, TX_E_START);
  3089. }
  3090. static void
  3091. bna_tx_stop(struct bna_tx *tx)
  3092. {
  3093. tx->stop_cbfn = bna_tx_mod_cb_tx_stopped;
  3094. tx->stop_cbarg = &tx->bna->tx_mod;
  3095. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3096. bfa_fsm_send_event(tx, TX_E_STOP);
  3097. }
  3098. static void
  3099. bna_tx_fail(struct bna_tx *tx)
  3100. {
  3101. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3102. bfa_fsm_send_event(tx, TX_E_FAIL);
  3103. }
  3104. static void
  3105. bna_tx_prio_changed(struct bna_tx *tx, int prio)
  3106. {
  3107. struct bna_txq *txq;
  3108. struct list_head *qe;
  3109. list_for_each(qe, &tx->txq_q) {
  3110. txq = (struct bna_txq *)qe;
  3111. txq->priority = prio;
  3112. }
  3113. bfa_fsm_send_event(tx, TX_E_PRIO_CHANGE);
  3114. }
  3115. static void
  3116. bna_tx_cee_link_status(struct bna_tx *tx, int cee_link)
  3117. {
  3118. if (cee_link)
  3119. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3120. else
  3121. tx->flags &= ~BNA_TX_F_PRIO_LOCK;
  3122. }
  3123. static void
  3124. bna_tx_mod_cb_tx_stopped(void *arg, struct bna_tx *tx,
  3125. enum bna_cb_status status)
  3126. {
  3127. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3128. bfa_wc_down(&tx_mod->tx_stop_wc);
  3129. }
  3130. static void
  3131. bna_tx_mod_cb_tx_stopped_all(void *arg)
  3132. {
  3133. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3134. if (tx_mod->stop_cbfn)
  3135. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3136. tx_mod->stop_cbfn = NULL;
  3137. }
  3138. void
  3139. bna_tx_res_req(int num_txq, int txq_depth, struct bna_res_info *res_info)
  3140. {
  3141. u32 q_size;
  3142. u32 page_count;
  3143. struct bna_mem_info *mem_info;
  3144. res_info[BNA_TX_RES_MEM_T_TCB].res_type = BNA_RES_T_MEM;
  3145. mem_info = &res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info;
  3146. mem_info->mem_type = BNA_MEM_T_KVA;
  3147. mem_info->len = sizeof(struct bna_tcb);
  3148. mem_info->num = num_txq;
  3149. q_size = txq_depth * BFI_TXQ_WI_SIZE;
  3150. q_size = ALIGN(q_size, PAGE_SIZE);
  3151. page_count = q_size >> PAGE_SHIFT;
  3152. res_info[BNA_TX_RES_MEM_T_QPT].res_type = BNA_RES_T_MEM;
  3153. mem_info = &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info;
  3154. mem_info->mem_type = BNA_MEM_T_DMA;
  3155. mem_info->len = page_count * sizeof(struct bna_dma_addr);
  3156. mem_info->num = num_txq;
  3157. res_info[BNA_TX_RES_MEM_T_SWQPT].res_type = BNA_RES_T_MEM;
  3158. mem_info = &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info;
  3159. mem_info->mem_type = BNA_MEM_T_KVA;
  3160. mem_info->len = page_count * sizeof(void *);
  3161. mem_info->num = num_txq;
  3162. res_info[BNA_TX_RES_MEM_T_PAGE].res_type = BNA_RES_T_MEM;
  3163. mem_info = &res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info;
  3164. mem_info->mem_type = BNA_MEM_T_DMA;
  3165. mem_info->len = PAGE_SIZE;
  3166. mem_info->num = num_txq * page_count;
  3167. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_type = BNA_RES_T_INTR;
  3168. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.intr_type =
  3169. BNA_INTR_T_MSIX;
  3170. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.num = num_txq;
  3171. }
  3172. struct bna_tx *
  3173. bna_tx_create(struct bna *bna, struct bnad *bnad,
  3174. struct bna_tx_config *tx_cfg,
  3175. struct bna_tx_event_cbfn *tx_cbfn,
  3176. struct bna_res_info *res_info, void *priv)
  3177. {
  3178. struct bna_intr_info *intr_info;
  3179. struct bna_tx_mod *tx_mod = &bna->tx_mod;
  3180. struct bna_tx *tx;
  3181. struct bna_txq *txq;
  3182. struct list_head *qe;
  3183. struct bna_ib_mod *ib_mod = &bna->ib_mod;
  3184. struct bna_doorbell_qset *qset;
  3185. struct bna_ib_config ib_config;
  3186. int page_count;
  3187. int page_size;
  3188. int page_idx;
  3189. int i;
  3190. unsigned long off;
  3191. intr_info = &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
  3192. page_count = (res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.num) /
  3193. tx_cfg->num_txq;
  3194. page_size = res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.len;
  3195. /**
  3196. * Get resources
  3197. */
  3198. if ((intr_info->num != 1) && (intr_info->num != tx_cfg->num_txq))
  3199. return NULL;
  3200. /* Tx */
  3201. if (list_empty(&tx_mod->tx_free_q))
  3202. return NULL;
  3203. bfa_q_deq(&tx_mod->tx_free_q, &tx);
  3204. bfa_q_qe_init(&tx->qe);
  3205. /* TxQs */
  3206. INIT_LIST_HEAD(&tx->txq_q);
  3207. for (i = 0; i < tx_cfg->num_txq; i++) {
  3208. if (list_empty(&tx_mod->txq_free_q))
  3209. goto err_return;
  3210. bfa_q_deq(&tx_mod->txq_free_q, &txq);
  3211. bfa_q_qe_init(&txq->qe);
  3212. list_add_tail(&txq->qe, &tx->txq_q);
  3213. txq->ib = NULL;
  3214. txq->ib_seg_offset = -1;
  3215. txq->tx = tx;
  3216. }
  3217. /* IBs */
  3218. i = 0;
  3219. list_for_each(qe, &tx->txq_q) {
  3220. txq = (struct bna_txq *)qe;
  3221. if (intr_info->num == 1)
  3222. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3223. intr_info->idl[0].vector);
  3224. else
  3225. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3226. intr_info->idl[i].vector);
  3227. if (txq->ib == NULL)
  3228. goto err_return;
  3229. txq->ib_seg_offset = bna_ib_reserve_idx(txq->ib);
  3230. if (txq->ib_seg_offset == -1)
  3231. goto err_return;
  3232. i++;
  3233. }
  3234. /*
  3235. * Initialize
  3236. */
  3237. /* Tx */
  3238. tx->tcb_setup_cbfn = tx_cbfn->tcb_setup_cbfn;
  3239. tx->tcb_destroy_cbfn = tx_cbfn->tcb_destroy_cbfn;
  3240. /* Following callbacks are mandatory */
  3241. tx->tx_stall_cbfn = tx_cbfn->tx_stall_cbfn;
  3242. tx->tx_resume_cbfn = tx_cbfn->tx_resume_cbfn;
  3243. tx->tx_cleanup_cbfn = tx_cbfn->tx_cleanup_cbfn;
  3244. list_add_tail(&tx->qe, &tx_mod->tx_active_q);
  3245. tx->bna = bna;
  3246. tx->priv = priv;
  3247. tx->txq_stop_wc.wc_resume = bna_tx_cb_txq_stopped_all;
  3248. tx->txq_stop_wc.wc_cbarg = tx;
  3249. tx->txq_stop_wc.wc_count = 0;
  3250. tx->type = tx_cfg->tx_type;
  3251. tx->flags = 0;
  3252. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_STARTED) {
  3253. switch (tx->type) {
  3254. case BNA_TX_T_REGULAR:
  3255. if (!(tx->bna->tx_mod.flags &
  3256. BNA_TX_MOD_F_PORT_LOOPBACK))
  3257. tx->flags |= BNA_TX_F_PORT_STARTED;
  3258. break;
  3259. case BNA_TX_T_LOOPBACK:
  3260. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_LOOPBACK)
  3261. tx->flags |= BNA_TX_F_PORT_STARTED;
  3262. break;
  3263. }
  3264. }
  3265. if (tx->bna->tx_mod.cee_link)
  3266. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3267. /* TxQ */
  3268. i = 0;
  3269. page_idx = 0;
  3270. list_for_each(qe, &tx->txq_q) {
  3271. txq = (struct bna_txq *)qe;
  3272. txq->priority = tx_mod->priority;
  3273. txq->tcb = (struct bna_tcb *)
  3274. res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info.mdl[i].kva;
  3275. txq->tx_packets = 0;
  3276. txq->tx_bytes = 0;
  3277. /* IB */
  3278. ib_config.coalescing_timeo = BFI_TX_COALESCING_TIMEO;
  3279. ib_config.interpkt_timeo = 0; /* Not used */
  3280. ib_config.interpkt_count = BFI_TX_INTERPKT_COUNT;
  3281. ib_config.ctrl_flags = (BFI_IB_CF_INTER_PKT_DMA |
  3282. BFI_IB_CF_INT_ENABLE |
  3283. BFI_IB_CF_COALESCING_MODE);
  3284. bna_ib_config(txq->ib, &ib_config);
  3285. /* TCB */
  3286. txq->tcb->producer_index = 0;
  3287. txq->tcb->consumer_index = 0;
  3288. txq->tcb->hw_consumer_index = (volatile u32 *)
  3289. ((volatile u8 *)txq->ib->ib_seg_host_addr_kva +
  3290. (txq->ib_seg_offset * BFI_IBIDX_SIZE));
  3291. *(txq->tcb->hw_consumer_index) = 0;
  3292. txq->tcb->q_depth = tx_cfg->txq_depth;
  3293. txq->tcb->unmap_q = (void *)
  3294. res_info[BNA_TX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[i].kva;
  3295. qset = (struct bna_doorbell_qset *)0;
  3296. off = (unsigned long)&qset[txq->txq_id].txq[0];
  3297. txq->tcb->q_dbell = off +
  3298. BNA_GET_DOORBELL_BASE_ADDR(bna->pcidev.pci_bar_kva);
  3299. txq->tcb->i_dbell = &txq->ib->door_bell;
  3300. txq->tcb->intr_type = intr_info->intr_type;
  3301. txq->tcb->intr_vector = (intr_info->num == 1) ?
  3302. intr_info->idl[0].vector :
  3303. intr_info->idl[i].vector;
  3304. txq->tcb->txq = txq;
  3305. txq->tcb->bnad = bnad;
  3306. txq->tcb->id = i;
  3307. /* QPT, SWQPT, Pages */
  3308. bna_txq_qpt_setup(txq, page_count, page_size,
  3309. &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info.mdl[i],
  3310. &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info.mdl[i],
  3311. &res_info[BNA_TX_RES_MEM_T_PAGE].
  3312. res_u.mem_info.mdl[page_idx]);
  3313. txq->tcb->page_idx = page_idx;
  3314. txq->tcb->page_count = page_count;
  3315. page_idx += page_count;
  3316. /* Callback to bnad for setting up TCB */
  3317. if (tx->tcb_setup_cbfn)
  3318. (tx->tcb_setup_cbfn)(bna->bnad, txq->tcb);
  3319. i++;
  3320. }
  3321. /* TxF */
  3322. tx->txf.ctrl_flags = BFI_TXF_CF_ENABLE | BFI_TXF_CF_VLAN_WI_BASED;
  3323. tx->txf.vlan = 0;
  3324. /* Mbox element */
  3325. bfa_q_qe_init(&tx->mbox_qe.qe);
  3326. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  3327. return tx;
  3328. err_return:
  3329. bna_tx_free(tx);
  3330. return NULL;
  3331. }
  3332. void
  3333. bna_tx_destroy(struct bna_tx *tx)
  3334. {
  3335. /* Callback to bnad for destroying TCB */
  3336. if (tx->tcb_destroy_cbfn) {
  3337. struct bna_txq *txq;
  3338. struct list_head *qe;
  3339. list_for_each(qe, &tx->txq_q) {
  3340. txq = (struct bna_txq *)qe;
  3341. (tx->tcb_destroy_cbfn)(tx->bna->bnad, txq->tcb);
  3342. }
  3343. }
  3344. bna_tx_free(tx);
  3345. }
  3346. void
  3347. bna_tx_enable(struct bna_tx *tx)
  3348. {
  3349. if (tx->fsm != (bfa_sm_t)bna_tx_sm_stopped)
  3350. return;
  3351. tx->flags |= BNA_TX_F_ENABLED;
  3352. if (tx->flags & BNA_TX_F_PORT_STARTED)
  3353. bfa_fsm_send_event(tx, TX_E_START);
  3354. }
  3355. void
  3356. bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
  3357. void (*cbfn)(void *, struct bna_tx *, enum bna_cb_status))
  3358. {
  3359. if (type == BNA_SOFT_CLEANUP) {
  3360. (*cbfn)(tx->bna->bnad, tx, BNA_CB_SUCCESS);
  3361. return;
  3362. }
  3363. tx->stop_cbfn = cbfn;
  3364. tx->stop_cbarg = tx->bna->bnad;
  3365. tx->flags &= ~BNA_TX_F_ENABLED;
  3366. bfa_fsm_send_event(tx, TX_E_STOP);
  3367. }
  3368. int
  3369. bna_tx_state_get(struct bna_tx *tx)
  3370. {
  3371. return bfa_sm_to_state(tx_sm_table, tx->fsm);
  3372. }
  3373. void
  3374. bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
  3375. struct bna_res_info *res_info)
  3376. {
  3377. int i;
  3378. tx_mod->bna = bna;
  3379. tx_mod->flags = 0;
  3380. tx_mod->tx = (struct bna_tx *)
  3381. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.mdl[0].kva;
  3382. tx_mod->txq = (struct bna_txq *)
  3383. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  3384. INIT_LIST_HEAD(&tx_mod->tx_free_q);
  3385. INIT_LIST_HEAD(&tx_mod->tx_active_q);
  3386. INIT_LIST_HEAD(&tx_mod->txq_free_q);
  3387. for (i = 0; i < BFI_MAX_TXQ; i++) {
  3388. tx_mod->tx[i].txf.txf_id = i;
  3389. bfa_q_qe_init(&tx_mod->tx[i].qe);
  3390. list_add_tail(&tx_mod->tx[i].qe, &tx_mod->tx_free_q);
  3391. tx_mod->txq[i].txq_id = i;
  3392. bfa_q_qe_init(&tx_mod->txq[i].qe);
  3393. list_add_tail(&tx_mod->txq[i].qe, &tx_mod->txq_free_q);
  3394. }
  3395. tx_mod->tx_stop_wc.wc_resume = bna_tx_mod_cb_tx_stopped_all;
  3396. tx_mod->tx_stop_wc.wc_cbarg = tx_mod;
  3397. tx_mod->tx_stop_wc.wc_count = 0;
  3398. }
  3399. void
  3400. bna_tx_mod_uninit(struct bna_tx_mod *tx_mod)
  3401. {
  3402. struct list_head *qe;
  3403. int i;
  3404. i = 0;
  3405. list_for_each(qe, &tx_mod->tx_free_q)
  3406. i++;
  3407. i = 0;
  3408. list_for_each(qe, &tx_mod->txq_free_q)
  3409. i++;
  3410. tx_mod->bna = NULL;
  3411. }
  3412. void
  3413. bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3414. {
  3415. struct bna_tx *tx;
  3416. struct list_head *qe;
  3417. tx_mod->flags |= BNA_TX_MOD_F_PORT_STARTED;
  3418. if (type == BNA_TX_T_LOOPBACK)
  3419. tx_mod->flags |= BNA_TX_MOD_F_PORT_LOOPBACK;
  3420. list_for_each(qe, &tx_mod->tx_active_q) {
  3421. tx = (struct bna_tx *)qe;
  3422. if (tx->type == type)
  3423. bna_tx_start(tx);
  3424. }
  3425. }
  3426. void
  3427. bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3428. {
  3429. struct bna_tx *tx;
  3430. struct list_head *qe;
  3431. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3432. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3433. tx_mod->stop_cbfn = bna_port_cb_tx_stopped;
  3434. /**
  3435. * Before calling bna_tx_stop(), increment tx_stop_wc as many times
  3436. * as we are going to call bna_tx_stop
  3437. */
  3438. list_for_each(qe, &tx_mod->tx_active_q) {
  3439. tx = (struct bna_tx *)qe;
  3440. if (tx->type == type)
  3441. bfa_wc_up(&tx_mod->tx_stop_wc);
  3442. }
  3443. if (tx_mod->tx_stop_wc.wc_count == 0) {
  3444. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3445. tx_mod->stop_cbfn = NULL;
  3446. return;
  3447. }
  3448. list_for_each(qe, &tx_mod->tx_active_q) {
  3449. tx = (struct bna_tx *)qe;
  3450. if (tx->type == type)
  3451. bna_tx_stop(tx);
  3452. }
  3453. }
  3454. void
  3455. bna_tx_mod_fail(struct bna_tx_mod *tx_mod)
  3456. {
  3457. struct bna_tx *tx;
  3458. struct list_head *qe;
  3459. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3460. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3461. list_for_each(qe, &tx_mod->tx_active_q) {
  3462. tx = (struct bna_tx *)qe;
  3463. bna_tx_fail(tx);
  3464. }
  3465. }
  3466. void
  3467. bna_tx_mod_prio_changed(struct bna_tx_mod *tx_mod, int prio)
  3468. {
  3469. struct bna_tx *tx;
  3470. struct list_head *qe;
  3471. if (prio != tx_mod->priority) {
  3472. tx_mod->priority = prio;
  3473. list_for_each(qe, &tx_mod->tx_active_q) {
  3474. tx = (struct bna_tx *)qe;
  3475. bna_tx_prio_changed(tx, prio);
  3476. }
  3477. }
  3478. }
  3479. void
  3480. bna_tx_mod_cee_link_status(struct bna_tx_mod *tx_mod, int cee_link)
  3481. {
  3482. struct bna_tx *tx;
  3483. struct list_head *qe;
  3484. tx_mod->cee_link = cee_link;
  3485. list_for_each(qe, &tx_mod->tx_active_q) {
  3486. tx = (struct bna_tx *)qe;
  3487. bna_tx_cee_link_status(tx, cee_link);
  3488. }
  3489. }