be_cmds.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /**
  2. * Copyright (C) 2005 - 2010 ServerEngines
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@serverengines.com
  12. *
  13. * ServerEngines
  14. * 209 N. Fair Oaks Ave
  15. * Sunnyvale, CA 94085
  16. */
  17. #include "be.h"
  18. #include "be_mgmt.h"
  19. #include "be_main.h"
  20. void be_mcc_notify(struct beiscsi_hba *phba)
  21. {
  22. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  23. u32 val = 0;
  24. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  25. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  26. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  27. }
  28. unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
  29. {
  30. unsigned int tag = 0;
  31. unsigned int num = 0;
  32. mcc_tag_rdy:
  33. if (phba->ctrl.mcc_tag_available) {
  34. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  35. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  36. phba->ctrl.mcc_numtag[tag] = 0;
  37. } else {
  38. udelay(100);
  39. num++;
  40. if (num < mcc_timeout)
  41. goto mcc_tag_rdy;
  42. }
  43. if (tag) {
  44. phba->ctrl.mcc_tag_available--;
  45. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  46. phba->ctrl.mcc_alloc_index = 0;
  47. else
  48. phba->ctrl.mcc_alloc_index++;
  49. }
  50. return tag;
  51. }
  52. void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
  53. {
  54. spin_lock(&ctrl->mbox_lock);
  55. tag = tag & 0x000000FF;
  56. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  57. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  58. ctrl->mcc_free_index = 0;
  59. else
  60. ctrl->mcc_free_index++;
  61. ctrl->mcc_tag_available++;
  62. spin_unlock(&ctrl->mbox_lock);
  63. }
  64. bool is_link_state_evt(u32 trailer)
  65. {
  66. return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
  67. ASYNC_TRAILER_EVENT_CODE_MASK) ==
  68. ASYNC_EVENT_CODE_LINK_STATE);
  69. }
  70. static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
  71. {
  72. if (compl->flags != 0) {
  73. compl->flags = le32_to_cpu(compl->flags);
  74. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  75. return true;
  76. } else
  77. return false;
  78. }
  79. static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
  80. {
  81. compl->flags = 0;
  82. }
  83. static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
  84. struct be_mcc_compl *compl)
  85. {
  86. u16 compl_status, extd_status;
  87. be_dws_le_to_cpu(compl, 4);
  88. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  89. CQE_STATUS_COMPL_MASK;
  90. if (compl_status != MCC_STATUS_SUCCESS) {
  91. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  92. CQE_STATUS_EXTD_MASK;
  93. dev_err(&ctrl->pdev->dev,
  94. "error in cmd completion: status(compl/extd)=%d/%d\n",
  95. compl_status, extd_status);
  96. return -1;
  97. }
  98. return 0;
  99. }
  100. int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
  101. struct be_mcc_compl *compl)
  102. {
  103. u16 compl_status, extd_status;
  104. unsigned short tag;
  105. be_dws_le_to_cpu(compl, 4);
  106. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  107. CQE_STATUS_COMPL_MASK;
  108. /* The ctrl.mcc_numtag[tag] is filled with
  109. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  110. * [7:0] = compl_status
  111. */
  112. tag = (compl->tag0 & 0x000000FF);
  113. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  114. CQE_STATUS_EXTD_MASK;
  115. ctrl->mcc_numtag[tag] = 0x80000000;
  116. ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
  117. ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
  118. ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
  119. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  120. return 0;
  121. }
  122. static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
  123. {
  124. struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
  125. struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
  126. if (be_mcc_compl_is_new(compl)) {
  127. queue_tail_inc(mcc_cq);
  128. return compl;
  129. }
  130. return NULL;
  131. }
  132. static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
  133. {
  134. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  135. }
  136. void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
  137. struct be_async_event_link_state *evt)
  138. {
  139. switch (evt->port_link_status) {
  140. case ASYNC_EVENT_LINK_DOWN:
  141. SE_DEBUG(DBG_LVL_1, "Link Down on Physical Port %d \n",
  142. evt->physical_port);
  143. phba->state |= BE_ADAPTER_LINK_DOWN;
  144. iscsi_host_for_each_session(phba->shost,
  145. be2iscsi_fail_session);
  146. break;
  147. case ASYNC_EVENT_LINK_UP:
  148. phba->state = BE_ADAPTER_UP;
  149. SE_DEBUG(DBG_LVL_1, "Link UP on Physical Port %d \n",
  150. evt->physical_port);
  151. break;
  152. default:
  153. SE_DEBUG(DBG_LVL_1, "Unexpected Async Notification %d on"
  154. "Physical Port %d \n",
  155. evt->port_link_status,
  156. evt->physical_port);
  157. }
  158. }
  159. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  160. u16 num_popped)
  161. {
  162. u32 val = 0;
  163. val |= qid & DB_CQ_RING_ID_MASK;
  164. if (arm)
  165. val |= 1 << DB_CQ_REARM_SHIFT;
  166. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  167. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  168. }
  169. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  170. {
  171. struct be_mcc_compl *compl;
  172. int num = 0, status = 0;
  173. struct be_ctrl_info *ctrl = &phba->ctrl;
  174. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  175. while ((compl = be_mcc_compl_get(phba))) {
  176. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  177. /* Interpret flags as an async trailer */
  178. if (is_link_state_evt(compl->flags))
  179. /* Interpret compl as a async link evt */
  180. beiscsi_async_link_state_process(phba,
  181. (struct be_async_event_link_state *) compl);
  182. else
  183. SE_DEBUG(DBG_LVL_1,
  184. " Unsupported Async Event, flags"
  185. " = 0x%08x \n", compl->flags);
  186. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  187. status = be_mcc_compl_process(ctrl, compl);
  188. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  189. }
  190. be_mcc_compl_use(compl);
  191. num++;
  192. }
  193. if (num)
  194. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  195. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  196. return status;
  197. }
  198. /* Wait till no more pending mcc requests are present */
  199. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  200. {
  201. int i, status;
  202. for (i = 0; i < mcc_timeout; i++) {
  203. status = beiscsi_process_mcc(phba);
  204. if (status)
  205. return status;
  206. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  207. break;
  208. udelay(100);
  209. }
  210. if (i == mcc_timeout) {
  211. dev_err(&phba->pcidev->dev, "mccq poll timed out\n");
  212. return -1;
  213. }
  214. return 0;
  215. }
  216. /* Notify MCC requests and wait for completion */
  217. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  218. {
  219. be_mcc_notify(phba);
  220. return be_mcc_wait_compl(phba);
  221. }
  222. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  223. {
  224. #define long_delay 2000
  225. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  226. int cnt = 0, wait = 5; /* in usecs */
  227. u32 ready;
  228. do {
  229. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  230. if (ready)
  231. break;
  232. if (cnt > 6000000) {
  233. dev_err(&ctrl->pdev->dev, "mbox_db poll timed out\n");
  234. return -1;
  235. }
  236. if (cnt > 50) {
  237. wait = long_delay;
  238. mdelay(long_delay / 1000);
  239. } else
  240. udelay(wait);
  241. cnt += wait;
  242. } while (true);
  243. return 0;
  244. }
  245. int be_mbox_notify(struct be_ctrl_info *ctrl)
  246. {
  247. int status;
  248. u32 val = 0;
  249. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  250. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  251. struct be_mcc_mailbox *mbox = mbox_mem->va;
  252. struct be_mcc_compl *compl = &mbox->compl;
  253. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  254. val |= MPU_MAILBOX_DB_HI_MASK;
  255. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  256. iowrite32(val, db);
  257. status = be_mbox_db_ready_wait(ctrl);
  258. if (status != 0) {
  259. SE_DEBUG(DBG_LVL_1, " be_mbox_db_ready_wait failed 1\n");
  260. return status;
  261. }
  262. val = 0;
  263. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  264. val &= ~MPU_MAILBOX_DB_HI_MASK;
  265. val |= (u32) (mbox_mem->dma >> 4) << 2;
  266. iowrite32(val, db);
  267. status = be_mbox_db_ready_wait(ctrl);
  268. if (status != 0) {
  269. SE_DEBUG(DBG_LVL_1, " be_mbox_db_ready_wait failed 2\n");
  270. return status;
  271. }
  272. if (be_mcc_compl_is_new(compl)) {
  273. status = be_mcc_compl_process(ctrl, &mbox->compl);
  274. be_mcc_compl_use(compl);
  275. if (status) {
  276. SE_DEBUG(DBG_LVL_1, "After be_mcc_compl_process \n");
  277. return status;
  278. }
  279. } else {
  280. dev_err(&ctrl->pdev->dev, "invalid mailbox completion\n");
  281. return -1;
  282. }
  283. return 0;
  284. }
  285. /*
  286. * Insert the mailbox address into the doorbell in two steps
  287. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  288. */
  289. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  290. {
  291. int status;
  292. u32 val = 0;
  293. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  294. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  295. struct be_mcc_mailbox *mbox = mbox_mem->va;
  296. struct be_mcc_compl *compl = &mbox->compl;
  297. struct be_ctrl_info *ctrl = &phba->ctrl;
  298. val |= MPU_MAILBOX_DB_HI_MASK;
  299. /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
  300. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  301. iowrite32(val, db);
  302. /* wait for ready to be set */
  303. status = be_mbox_db_ready_wait(ctrl);
  304. if (status != 0)
  305. return status;
  306. val = 0;
  307. /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
  308. val |= (u32)(mbox_mem->dma >> 4) << 2;
  309. iowrite32(val, db);
  310. status = be_mbox_db_ready_wait(ctrl);
  311. if (status != 0)
  312. return status;
  313. /* A cq entry has been made now */
  314. if (be_mcc_compl_is_new(compl)) {
  315. status = be_mcc_compl_process(ctrl, &mbox->compl);
  316. be_mcc_compl_use(compl);
  317. if (status)
  318. return status;
  319. } else {
  320. dev_err(&phba->pcidev->dev, "invalid mailbox completion\n");
  321. return -1;
  322. }
  323. return 0;
  324. }
  325. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  326. bool embedded, u8 sge_cnt)
  327. {
  328. if (embedded)
  329. wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
  330. else
  331. wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  332. MCC_WRB_SGE_CNT_SHIFT;
  333. wrb->payload_length = payload_len;
  334. be_dws_cpu_to_le(wrb, 8);
  335. }
  336. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  337. u8 subsystem, u8 opcode, int cmd_len)
  338. {
  339. req_hdr->opcode = opcode;
  340. req_hdr->subsystem = subsystem;
  341. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  342. }
  343. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  344. struct be_dma_mem *mem)
  345. {
  346. int i, buf_pages;
  347. u64 dma = (u64) mem->dma;
  348. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  349. for (i = 0; i < buf_pages; i++) {
  350. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  351. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  352. dma += PAGE_SIZE_4K;
  353. }
  354. }
  355. static u32 eq_delay_to_mult(u32 usec_delay)
  356. {
  357. #define MAX_INTR_RATE 651042
  358. const u32 round = 10;
  359. u32 multiplier;
  360. if (usec_delay == 0)
  361. multiplier = 0;
  362. else {
  363. u32 interrupt_rate = 1000000 / usec_delay;
  364. if (interrupt_rate == 0)
  365. multiplier = 1023;
  366. else {
  367. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  368. multiplier /= interrupt_rate;
  369. multiplier = (multiplier + round / 2) / round;
  370. multiplier = min(multiplier, (u32) 1023);
  371. }
  372. }
  373. return multiplier;
  374. }
  375. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  376. {
  377. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  378. }
  379. struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
  380. {
  381. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  382. struct be_mcc_wrb *wrb;
  383. BUG_ON(atomic_read(&mccq->used) >= mccq->len);
  384. wrb = queue_head_node(mccq);
  385. memset(wrb, 0, sizeof(*wrb));
  386. wrb->tag0 = (mccq->head & 0x000000FF) << 16;
  387. queue_head_inc(mccq);
  388. atomic_inc(&mccq->used);
  389. return wrb;
  390. }
  391. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  392. struct be_queue_info *eq, int eq_delay)
  393. {
  394. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  395. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  396. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  397. struct be_dma_mem *q_mem = &eq->dma_mem;
  398. int status;
  399. SE_DEBUG(DBG_LVL_8, "In beiscsi_cmd_eq_create\n");
  400. spin_lock(&ctrl->mbox_lock);
  401. memset(wrb, 0, sizeof(*wrb));
  402. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  403. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  404. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  405. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  406. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  407. PCI_FUNC(ctrl->pdev->devfn));
  408. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  409. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  410. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  411. __ilog2_u32(eq->len / 256));
  412. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  413. eq_delay_to_mult(eq_delay));
  414. be_dws_cpu_to_le(req->context, sizeof(req->context));
  415. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  416. status = be_mbox_notify(ctrl);
  417. if (!status) {
  418. eq->id = le16_to_cpu(resp->eq_id);
  419. eq->created = true;
  420. }
  421. spin_unlock(&ctrl->mbox_lock);
  422. return status;
  423. }
  424. int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
  425. {
  426. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  427. int status;
  428. u8 *endian_check;
  429. SE_DEBUG(DBG_LVL_8, "In be_cmd_fw_initialize\n");
  430. spin_lock(&ctrl->mbox_lock);
  431. memset(wrb, 0, sizeof(*wrb));
  432. endian_check = (u8 *) wrb;
  433. *endian_check++ = 0xFF;
  434. *endian_check++ = 0x12;
  435. *endian_check++ = 0x34;
  436. *endian_check++ = 0xFF;
  437. *endian_check++ = 0xFF;
  438. *endian_check++ = 0x56;
  439. *endian_check++ = 0x78;
  440. *endian_check++ = 0xFF;
  441. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  442. status = be_mbox_notify(ctrl);
  443. if (status)
  444. SE_DEBUG(DBG_LVL_1, "be_cmd_fw_initialize Failed \n");
  445. spin_unlock(&ctrl->mbox_lock);
  446. return status;
  447. }
  448. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  449. struct be_queue_info *cq, struct be_queue_info *eq,
  450. bool sol_evts, bool no_delay, int coalesce_wm)
  451. {
  452. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  453. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  454. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  455. struct be_dma_mem *q_mem = &cq->dma_mem;
  456. void *ctxt = &req->context;
  457. int status;
  458. SE_DEBUG(DBG_LVL_8, "In beiscsi_cmd_cq_create \n");
  459. spin_lock(&ctrl->mbox_lock);
  460. memset(wrb, 0, sizeof(*wrb));
  461. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  462. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  463. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  464. if (!q_mem->va)
  465. SE_DEBUG(DBG_LVL_1, "uninitialized q_mem->va\n");
  466. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  467. AMAP_SET_BITS(struct amap_cq_context, coalescwm, ctxt, coalesce_wm);
  468. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  469. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  470. __ilog2_u32(cq->len / 256));
  471. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  472. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  473. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  474. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  475. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  476. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  477. PCI_FUNC(ctrl->pdev->devfn));
  478. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  479. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  480. status = be_mbox_notify(ctrl);
  481. if (!status) {
  482. cq->id = le16_to_cpu(resp->cq_id);
  483. cq->created = true;
  484. } else
  485. SE_DEBUG(DBG_LVL_1, "In be_cmd_cq_create, status=ox%08x \n",
  486. status);
  487. spin_unlock(&ctrl->mbox_lock);
  488. return status;
  489. }
  490. static u32 be_encoded_q_len(int q_len)
  491. {
  492. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  493. if (len_encoded == 16)
  494. len_encoded = 0;
  495. return len_encoded;
  496. }
  497. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  498. struct be_queue_info *mccq,
  499. struct be_queue_info *cq)
  500. {
  501. struct be_mcc_wrb *wrb;
  502. struct be_cmd_req_mcc_create *req;
  503. struct be_dma_mem *q_mem = &mccq->dma_mem;
  504. struct be_ctrl_info *ctrl;
  505. void *ctxt;
  506. int status;
  507. spin_lock(&phba->ctrl.mbox_lock);
  508. ctrl = &phba->ctrl;
  509. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  510. req = embedded_payload(wrb);
  511. ctxt = &req->context;
  512. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  513. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  514. OPCODE_COMMON_MCC_CREATE, sizeof(*req));
  515. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  516. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  517. PCI_FUNC(phba->pcidev->devfn));
  518. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  519. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  520. be_encoded_q_len(mccq->len));
  521. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  522. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  523. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  524. status = be_mbox_notify_wait(phba);
  525. if (!status) {
  526. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  527. mccq->id = le16_to_cpu(resp->id);
  528. mccq->created = true;
  529. }
  530. spin_unlock(&phba->ctrl.mbox_lock);
  531. return status;
  532. }
  533. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  534. int queue_type)
  535. {
  536. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  537. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  538. u8 subsys = 0, opcode = 0;
  539. int status;
  540. SE_DEBUG(DBG_LVL_8, "In beiscsi_cmd_q_destroy \n");
  541. spin_lock(&ctrl->mbox_lock);
  542. memset(wrb, 0, sizeof(*wrb));
  543. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  544. switch (queue_type) {
  545. case QTYPE_EQ:
  546. subsys = CMD_SUBSYSTEM_COMMON;
  547. opcode = OPCODE_COMMON_EQ_DESTROY;
  548. break;
  549. case QTYPE_CQ:
  550. subsys = CMD_SUBSYSTEM_COMMON;
  551. opcode = OPCODE_COMMON_CQ_DESTROY;
  552. break;
  553. case QTYPE_MCCQ:
  554. subsys = CMD_SUBSYSTEM_COMMON;
  555. opcode = OPCODE_COMMON_MCC_DESTROY;
  556. break;
  557. case QTYPE_WRBQ:
  558. subsys = CMD_SUBSYSTEM_ISCSI;
  559. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  560. break;
  561. case QTYPE_DPDUQ:
  562. subsys = CMD_SUBSYSTEM_ISCSI;
  563. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  564. break;
  565. case QTYPE_SGL:
  566. subsys = CMD_SUBSYSTEM_ISCSI;
  567. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  568. break;
  569. default:
  570. spin_unlock(&ctrl->mbox_lock);
  571. BUG();
  572. return -1;
  573. }
  574. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  575. if (queue_type != QTYPE_SGL)
  576. req->id = cpu_to_le16(q->id);
  577. status = be_mbox_notify(ctrl);
  578. spin_unlock(&ctrl->mbox_lock);
  579. return status;
  580. }
  581. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  582. struct be_queue_info *cq,
  583. struct be_queue_info *dq, int length,
  584. int entry_size)
  585. {
  586. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  587. struct be_defq_create_req *req = embedded_payload(wrb);
  588. struct be_dma_mem *q_mem = &dq->dma_mem;
  589. void *ctxt = &req->context;
  590. int status;
  591. SE_DEBUG(DBG_LVL_8, "In be_cmd_create_default_pdu_queue\n");
  592. spin_lock(&ctrl->mbox_lock);
  593. memset(wrb, 0, sizeof(*wrb));
  594. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  595. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  596. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  597. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  598. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid, ctxt, 0);
  599. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid_valid, ctxt,
  600. 1);
  601. AMAP_SET_BITS(struct amap_be_default_pdu_context, pci_func_id, ctxt,
  602. PCI_FUNC(ctrl->pdev->devfn));
  603. AMAP_SET_BITS(struct amap_be_default_pdu_context, ring_size, ctxt,
  604. be_encoded_q_len(length / sizeof(struct phys_addr)));
  605. AMAP_SET_BITS(struct amap_be_default_pdu_context, default_buffer_size,
  606. ctxt, entry_size);
  607. AMAP_SET_BITS(struct amap_be_default_pdu_context, cq_id_recv, ctxt,
  608. cq->id);
  609. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  610. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  611. status = be_mbox_notify(ctrl);
  612. if (!status) {
  613. struct be_defq_create_resp *resp = embedded_payload(wrb);
  614. dq->id = le16_to_cpu(resp->id);
  615. dq->created = true;
  616. }
  617. spin_unlock(&ctrl->mbox_lock);
  618. return status;
  619. }
  620. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
  621. struct be_queue_info *wrbq)
  622. {
  623. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  624. struct be_wrbq_create_req *req = embedded_payload(wrb);
  625. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  626. int status;
  627. spin_lock(&ctrl->mbox_lock);
  628. memset(wrb, 0, sizeof(*wrb));
  629. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  630. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  631. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  632. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  633. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  634. status = be_mbox_notify(ctrl);
  635. if (!status) {
  636. wrbq->id = le16_to_cpu(resp->cid);
  637. wrbq->created = true;
  638. }
  639. spin_unlock(&ctrl->mbox_lock);
  640. return status;
  641. }
  642. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  643. struct be_dma_mem *q_mem,
  644. u32 page_offset, u32 num_pages)
  645. {
  646. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  647. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  648. int status;
  649. unsigned int curr_pages;
  650. u32 internal_page_offset = 0;
  651. u32 temp_num_pages = num_pages;
  652. if (num_pages == 0xff)
  653. num_pages = 1;
  654. spin_lock(&ctrl->mbox_lock);
  655. do {
  656. memset(wrb, 0, sizeof(*wrb));
  657. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  658. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  659. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  660. sizeof(*req));
  661. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  662. pages);
  663. req->num_pages = min(num_pages, curr_pages);
  664. req->page_offset = page_offset;
  665. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  666. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  667. internal_page_offset += req->num_pages;
  668. page_offset += req->num_pages;
  669. num_pages -= req->num_pages;
  670. if (temp_num_pages == 0xff)
  671. req->num_pages = temp_num_pages;
  672. status = be_mbox_notify(ctrl);
  673. if (status) {
  674. SE_DEBUG(DBG_LVL_1,
  675. "FW CMD to map iscsi frags failed.\n");
  676. goto error;
  677. }
  678. } while (num_pages > 0);
  679. error:
  680. spin_unlock(&ctrl->mbox_lock);
  681. if (status != 0)
  682. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  683. return status;
  684. }