be_cmds.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. /**
  2. * Copyright (C) 2005 - 2013 Emulex
  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@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #include <scsi/iscsi_proto.h>
  18. #include "be_main.h"
  19. #include "be.h"
  20. #include "be_mgmt.h"
  21. int beiscsi_pci_soft_reset(struct beiscsi_hba *phba)
  22. {
  23. u32 sreset;
  24. u8 *pci_reset_offset = 0;
  25. u8 *pci_online0_offset = 0;
  26. u8 *pci_online1_offset = 0;
  27. u32 pconline0 = 0;
  28. u32 pconline1 = 0;
  29. u32 i;
  30. pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET;
  31. pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0;
  32. pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1;
  33. sreset = readl((void *)pci_reset_offset);
  34. sreset |= BE2_SET_RESET;
  35. writel(sreset, (void *)pci_reset_offset);
  36. i = 0;
  37. while (sreset & BE2_SET_RESET) {
  38. if (i > 64)
  39. break;
  40. msleep(100);
  41. sreset = readl((void *)pci_reset_offset);
  42. i++;
  43. }
  44. if (sreset & BE2_SET_RESET) {
  45. printk(KERN_ERR DRV_NAME
  46. " Soft Reset did not deassert\n");
  47. return -EIO;
  48. }
  49. pconline1 = BE2_MPU_IRAM_ONLINE;
  50. writel(pconline0, (void *)pci_online0_offset);
  51. writel(pconline1, (void *)pci_online1_offset);
  52. sreset |= BE2_SET_RESET;
  53. writel(sreset, (void *)pci_reset_offset);
  54. i = 0;
  55. while (sreset & BE2_SET_RESET) {
  56. if (i > 64)
  57. break;
  58. msleep(1);
  59. sreset = readl((void *)pci_reset_offset);
  60. i++;
  61. }
  62. if (sreset & BE2_SET_RESET) {
  63. printk(KERN_ERR DRV_NAME
  64. " MPU Online Soft Reset did not deassert\n");
  65. return -EIO;
  66. }
  67. return 0;
  68. }
  69. int be_chk_reset_complete(struct beiscsi_hba *phba)
  70. {
  71. unsigned int num_loop;
  72. u8 *mpu_sem = 0;
  73. u32 status;
  74. num_loop = 1000;
  75. mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  76. msleep(5000);
  77. while (num_loop) {
  78. status = readl((void *)mpu_sem);
  79. if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000)
  80. break;
  81. msleep(60);
  82. num_loop--;
  83. }
  84. if ((status & 0x80000000) || (!num_loop)) {
  85. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  86. "BC_%d : Failed in be_chk_reset_complete"
  87. "status = 0x%x\n", status);
  88. return -EIO;
  89. }
  90. return 0;
  91. }
  92. void be_mcc_notify(struct beiscsi_hba *phba)
  93. {
  94. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  95. u32 val = 0;
  96. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  97. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  98. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  99. }
  100. unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
  101. {
  102. unsigned int tag = 0;
  103. if (phba->ctrl.mcc_tag_available) {
  104. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  105. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  106. phba->ctrl.mcc_numtag[tag] = 0;
  107. }
  108. if (tag) {
  109. phba->ctrl.mcc_tag_available--;
  110. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  111. phba->ctrl.mcc_alloc_index = 0;
  112. else
  113. phba->ctrl.mcc_alloc_index++;
  114. }
  115. return tag;
  116. }
  117. /*
  118. * beiscsi_mccq_compl()- Wait for completion of MBX
  119. * @phba: Driver private structure
  120. * @tag: Tag for the MBX Command
  121. * @wrb: the WRB used for the MBX Command
  122. * @cmd_hdr: IOCTL Hdr for the MBX Cmd
  123. *
  124. * Waits for MBX completion with the passed TAG.
  125. *
  126. * return
  127. * Success: 0
  128. * Failure: Non-Zero
  129. **/
  130. int beiscsi_mccq_compl(struct beiscsi_hba *phba,
  131. uint32_t tag, struct be_mcc_wrb **wrb,
  132. void *cmd_hdr)
  133. {
  134. int rc = 0;
  135. uint32_t mcc_tag_response;
  136. uint16_t status = 0, addl_status = 0, wrb_num = 0;
  137. struct be_mcc_wrb *temp_wrb;
  138. struct be_cmd_req_hdr *ioctl_hdr;
  139. struct be_cmd_resp_hdr *ioctl_resp_hdr;
  140. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  141. if (beiscsi_error(phba))
  142. return -EIO;
  143. /* wait for the mccq completion */
  144. rc = wait_event_interruptible_timeout(
  145. phba->ctrl.mcc_wait[tag],
  146. phba->ctrl.mcc_numtag[tag],
  147. msecs_to_jiffies(
  148. BEISCSI_HOST_MBX_TIMEOUT));
  149. if (rc <= 0) {
  150. beiscsi_log(phba, KERN_ERR,
  151. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  152. BEISCSI_LOG_CONFIG,
  153. "BC_%d : MBX Cmd Completion timed out\n");
  154. rc = -EAGAIN;
  155. /* decrement the mccq used count */
  156. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  157. goto release_mcc_tag;
  158. } else
  159. rc = 0;
  160. mcc_tag_response = phba->ctrl.mcc_numtag[tag];
  161. status = (mcc_tag_response & CQE_STATUS_MASK);
  162. addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
  163. CQE_STATUS_ADDL_SHIFT);
  164. if (cmd_hdr) {
  165. ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
  166. } else {
  167. wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
  168. CQE_STATUS_WRB_SHIFT;
  169. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  170. ioctl_hdr = embedded_payload(temp_wrb);
  171. if (wrb)
  172. *wrb = temp_wrb;
  173. }
  174. if (status || addl_status) {
  175. beiscsi_log(phba, KERN_ERR,
  176. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  177. BEISCSI_LOG_CONFIG,
  178. "BC_%d : MBX Cmd Failed for "
  179. "Subsys : %d Opcode : %d with "
  180. "Status : %d and Extd_Status : %d\n",
  181. ioctl_hdr->subsystem,
  182. ioctl_hdr->opcode,
  183. status, addl_status);
  184. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  185. ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
  186. if (ioctl_resp_hdr->response_length)
  187. goto release_mcc_tag;
  188. }
  189. rc = -EAGAIN;
  190. }
  191. release_mcc_tag:
  192. /* Release the MCC entry */
  193. free_mcc_tag(&phba->ctrl, tag);
  194. return rc;
  195. }
  196. void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
  197. {
  198. spin_lock(&ctrl->mbox_lock);
  199. tag = tag & 0x000000FF;
  200. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  201. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  202. ctrl->mcc_free_index = 0;
  203. else
  204. ctrl->mcc_free_index++;
  205. ctrl->mcc_tag_available++;
  206. spin_unlock(&ctrl->mbox_lock);
  207. }
  208. bool is_link_state_evt(u32 trailer)
  209. {
  210. return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
  211. ASYNC_TRAILER_EVENT_CODE_MASK) ==
  212. ASYNC_EVENT_CODE_LINK_STATE);
  213. }
  214. static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
  215. {
  216. if (compl->flags != 0) {
  217. compl->flags = le32_to_cpu(compl->flags);
  218. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  219. return true;
  220. } else
  221. return false;
  222. }
  223. static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
  224. {
  225. compl->flags = 0;
  226. }
  227. /*
  228. * be_mcc_compl_process()- Check the MBX comapletion status
  229. * @ctrl: Function specific MBX data structure
  230. * @compl: Completion status of MBX Command
  231. *
  232. * Check for the MBX completion status when BMBX method used
  233. *
  234. * return
  235. * Success: Zero
  236. * Failure: Non-Zero
  237. **/
  238. static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
  239. struct be_mcc_compl *compl)
  240. {
  241. u16 compl_status, extd_status;
  242. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  243. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  244. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  245. struct be_cmd_resp_hdr *resp_hdr;
  246. be_dws_le_to_cpu(compl, 4);
  247. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  248. CQE_STATUS_COMPL_MASK;
  249. if (compl_status != MCC_STATUS_SUCCESS) {
  250. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  251. CQE_STATUS_EXTD_MASK;
  252. beiscsi_log(phba, KERN_ERR,
  253. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  254. "BC_%d : error in cmd completion: "
  255. "Subsystem : %d Opcode : %d "
  256. "status(compl/extd)=%d/%d\n",
  257. hdr->subsystem, hdr->opcode,
  258. compl_status, extd_status);
  259. if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  260. resp_hdr = (struct be_cmd_resp_hdr *) hdr;
  261. if (resp_hdr->response_length)
  262. return 0;
  263. }
  264. return -EBUSY;
  265. }
  266. return 0;
  267. }
  268. int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
  269. struct be_mcc_compl *compl)
  270. {
  271. u16 compl_status, extd_status;
  272. unsigned short tag;
  273. be_dws_le_to_cpu(compl, 4);
  274. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  275. CQE_STATUS_COMPL_MASK;
  276. /* The ctrl.mcc_numtag[tag] is filled with
  277. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  278. * [7:0] = compl_status
  279. */
  280. tag = (compl->tag0 & 0x000000FF);
  281. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  282. CQE_STATUS_EXTD_MASK;
  283. ctrl->mcc_numtag[tag] = 0x80000000;
  284. ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
  285. ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
  286. ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
  287. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  288. return 0;
  289. }
  290. static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
  291. {
  292. struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
  293. struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
  294. if (be_mcc_compl_is_new(compl)) {
  295. queue_tail_inc(mcc_cq);
  296. return compl;
  297. }
  298. return NULL;
  299. }
  300. static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
  301. {
  302. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  303. }
  304. void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
  305. struct be_async_event_link_state *evt)
  306. {
  307. if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
  308. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  309. (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
  310. phba->state = BE_ADAPTER_LINK_DOWN;
  311. beiscsi_log(phba, KERN_ERR,
  312. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  313. "BC_%d : Link Down on Port %d\n",
  314. evt->physical_port);
  315. iscsi_host_for_each_session(phba->shost,
  316. be2iscsi_fail_session);
  317. } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
  318. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  319. (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
  320. phba->state = BE_ADAPTER_UP;
  321. beiscsi_log(phba, KERN_ERR,
  322. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  323. "BC_%d : Link UP on Port %d\n",
  324. evt->physical_port);
  325. }
  326. }
  327. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  328. u16 num_popped)
  329. {
  330. u32 val = 0;
  331. val |= qid & DB_CQ_RING_ID_MASK;
  332. if (arm)
  333. val |= 1 << DB_CQ_REARM_SHIFT;
  334. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  335. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  336. }
  337. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  338. {
  339. struct be_mcc_compl *compl;
  340. int num = 0, status = 0;
  341. struct be_ctrl_info *ctrl = &phba->ctrl;
  342. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  343. while ((compl = be_mcc_compl_get(phba))) {
  344. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  345. /* Interpret flags as an async trailer */
  346. if (is_link_state_evt(compl->flags))
  347. /* Interpret compl as a async link evt */
  348. beiscsi_async_link_state_process(phba,
  349. (struct be_async_event_link_state *) compl);
  350. else
  351. beiscsi_log(phba, KERN_ERR,
  352. BEISCSI_LOG_CONFIG |
  353. BEISCSI_LOG_MBOX,
  354. "BC_%d : Unsupported Async Event, flags"
  355. " = 0x%08x\n", compl->flags);
  356. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  357. status = be_mcc_compl_process(ctrl, compl);
  358. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  359. }
  360. be_mcc_compl_use(compl);
  361. num++;
  362. }
  363. if (num)
  364. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  365. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  366. return status;
  367. }
  368. /*
  369. * be_mcc_wait_compl()- Wait for MBX completion
  370. * @phba: driver private structure
  371. *
  372. * Wait till no more pending mcc requests are present
  373. *
  374. * return
  375. * Success: 0
  376. * Failure: Non-Zero
  377. *
  378. **/
  379. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  380. {
  381. int i, status;
  382. for (i = 0; i < mcc_timeout; i++) {
  383. if (beiscsi_error(phba))
  384. return -EIO;
  385. status = beiscsi_process_mcc(phba);
  386. if (status)
  387. return status;
  388. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  389. break;
  390. udelay(100);
  391. }
  392. if (i == mcc_timeout) {
  393. beiscsi_log(phba, KERN_ERR,
  394. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  395. "BC_%d : FW Timed Out\n");
  396. phba->fw_timeout = true;
  397. beiscsi_ue_detect(phba);
  398. return -EBUSY;
  399. }
  400. return 0;
  401. }
  402. /*
  403. * be_mcc_notify_wait()- Notify and wait for Compl
  404. * @phba: driver private structure
  405. *
  406. * Notify MCC requests and wait for completion
  407. *
  408. * return
  409. * Success: 0
  410. * Failure: Non-Zero
  411. **/
  412. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  413. {
  414. be_mcc_notify(phba);
  415. return be_mcc_wait_compl(phba);
  416. }
  417. /*
  418. * be_mbox_db_ready_wait()- Check ready status
  419. * @ctrl: Function specific MBX data structure
  420. *
  421. * Check for the ready status of FW to send BMBX
  422. * commands to adapter.
  423. *
  424. * return
  425. * Success: 0
  426. * Failure: Non-Zero
  427. **/
  428. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  429. {
  430. #define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */
  431. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  432. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  433. unsigned long timeout;
  434. bool read_flag = false;
  435. int ret = 0, i;
  436. u32 ready;
  437. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q);
  438. if (beiscsi_error(phba))
  439. return -EIO;
  440. timeout = jiffies + (HZ * 110);
  441. do {
  442. for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) {
  443. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  444. if (ready) {
  445. read_flag = true;
  446. break;
  447. }
  448. mdelay(1);
  449. }
  450. if (!read_flag) {
  451. wait_event_timeout(rdybit_check_q,
  452. (read_flag != true),
  453. HZ * 5);
  454. }
  455. } while ((time_before(jiffies, timeout)) && !read_flag);
  456. if (!read_flag) {
  457. beiscsi_log(phba, KERN_ERR,
  458. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  459. "BC_%d : FW Timed Out\n");
  460. phba->fw_timeout = true;
  461. beiscsi_ue_detect(phba);
  462. ret = -EBUSY;
  463. }
  464. return ret;
  465. }
  466. /*
  467. * be_mbox_notify: Notify adapter of new BMBX command
  468. * @ctrl: Function specific MBX data structure
  469. *
  470. * Ring doorbell to inform adapter of a BMBX command
  471. * to process
  472. *
  473. * return
  474. * Success: 0
  475. * Failure: Non-Zero
  476. **/
  477. int be_mbox_notify(struct be_ctrl_info *ctrl)
  478. {
  479. int status;
  480. u32 val = 0;
  481. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  482. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  483. struct be_mcc_mailbox *mbox = mbox_mem->va;
  484. struct be_mcc_compl *compl = &mbox->compl;
  485. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  486. status = be_mbox_db_ready_wait(ctrl);
  487. if (status)
  488. return status;
  489. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  490. val |= MPU_MAILBOX_DB_HI_MASK;
  491. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  492. iowrite32(val, db);
  493. status = be_mbox_db_ready_wait(ctrl);
  494. if (status)
  495. return status;
  496. val = 0;
  497. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  498. val &= ~MPU_MAILBOX_DB_HI_MASK;
  499. val |= (u32) (mbox_mem->dma >> 4) << 2;
  500. iowrite32(val, db);
  501. status = be_mbox_db_ready_wait(ctrl);
  502. if (status)
  503. return status;
  504. if (be_mcc_compl_is_new(compl)) {
  505. status = be_mcc_compl_process(ctrl, &mbox->compl);
  506. be_mcc_compl_use(compl);
  507. if (status) {
  508. beiscsi_log(phba, KERN_ERR,
  509. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  510. "BC_%d : After be_mcc_compl_process\n");
  511. return status;
  512. }
  513. } else {
  514. beiscsi_log(phba, KERN_ERR,
  515. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  516. "BC_%d : Invalid Mailbox Completion\n");
  517. return -EBUSY;
  518. }
  519. return 0;
  520. }
  521. /*
  522. * Insert the mailbox address into the doorbell in two steps
  523. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  524. */
  525. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  526. {
  527. int status;
  528. u32 val = 0;
  529. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  530. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  531. struct be_mcc_mailbox *mbox = mbox_mem->va;
  532. struct be_mcc_compl *compl = &mbox->compl;
  533. struct be_ctrl_info *ctrl = &phba->ctrl;
  534. status = be_mbox_db_ready_wait(ctrl);
  535. if (status)
  536. return status;
  537. val |= MPU_MAILBOX_DB_HI_MASK;
  538. /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
  539. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  540. iowrite32(val, db);
  541. /* wait for ready to be set */
  542. status = be_mbox_db_ready_wait(ctrl);
  543. if (status != 0)
  544. return status;
  545. val = 0;
  546. /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
  547. val |= (u32)(mbox_mem->dma >> 4) << 2;
  548. iowrite32(val, db);
  549. status = be_mbox_db_ready_wait(ctrl);
  550. if (status != 0)
  551. return status;
  552. /* A cq entry has been made now */
  553. if (be_mcc_compl_is_new(compl)) {
  554. status = be_mcc_compl_process(ctrl, &mbox->compl);
  555. be_mcc_compl_use(compl);
  556. if (status)
  557. return status;
  558. } else {
  559. beiscsi_log(phba, KERN_ERR,
  560. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  561. "BC_%d : invalid mailbox completion\n");
  562. return -EBUSY;
  563. }
  564. return 0;
  565. }
  566. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  567. bool embedded, u8 sge_cnt)
  568. {
  569. if (embedded)
  570. wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
  571. else
  572. wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  573. MCC_WRB_SGE_CNT_SHIFT;
  574. wrb->payload_length = payload_len;
  575. be_dws_cpu_to_le(wrb, 8);
  576. }
  577. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  578. u8 subsystem, u8 opcode, int cmd_len)
  579. {
  580. req_hdr->opcode = opcode;
  581. req_hdr->subsystem = subsystem;
  582. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  583. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  584. }
  585. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  586. struct be_dma_mem *mem)
  587. {
  588. int i, buf_pages;
  589. u64 dma = (u64) mem->dma;
  590. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  591. for (i = 0; i < buf_pages; i++) {
  592. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  593. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  594. dma += PAGE_SIZE_4K;
  595. }
  596. }
  597. static u32 eq_delay_to_mult(u32 usec_delay)
  598. {
  599. #define MAX_INTR_RATE 651042
  600. const u32 round = 10;
  601. u32 multiplier;
  602. if (usec_delay == 0)
  603. multiplier = 0;
  604. else {
  605. u32 interrupt_rate = 1000000 / usec_delay;
  606. if (interrupt_rate == 0)
  607. multiplier = 1023;
  608. else {
  609. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  610. multiplier /= interrupt_rate;
  611. multiplier = (multiplier + round / 2) / round;
  612. multiplier = min(multiplier, (u32) 1023);
  613. }
  614. }
  615. return multiplier;
  616. }
  617. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  618. {
  619. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  620. }
  621. struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
  622. {
  623. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  624. struct be_mcc_wrb *wrb;
  625. WARN_ON(atomic_read(&mccq->used) >= mccq->len);
  626. wrb = queue_head_node(mccq);
  627. memset(wrb, 0, sizeof(*wrb));
  628. wrb->tag0 = (mccq->head & 0x000000FF) << 16;
  629. queue_head_inc(mccq);
  630. atomic_inc(&mccq->used);
  631. return wrb;
  632. }
  633. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  634. struct be_queue_info *eq, int eq_delay)
  635. {
  636. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  637. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  638. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  639. struct be_dma_mem *q_mem = &eq->dma_mem;
  640. int status;
  641. spin_lock(&ctrl->mbox_lock);
  642. memset(wrb, 0, sizeof(*wrb));
  643. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  644. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  645. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  646. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  647. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  648. PCI_FUNC(ctrl->pdev->devfn));
  649. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  650. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  651. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  652. __ilog2_u32(eq->len / 256));
  653. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  654. eq_delay_to_mult(eq_delay));
  655. be_dws_cpu_to_le(req->context, sizeof(req->context));
  656. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  657. status = be_mbox_notify(ctrl);
  658. if (!status) {
  659. eq->id = le16_to_cpu(resp->eq_id);
  660. eq->created = true;
  661. }
  662. spin_unlock(&ctrl->mbox_lock);
  663. return status;
  664. }
  665. /**
  666. * be_cmd_fw_initialize()- Initialize FW
  667. * @ctrl: Pointer to function control structure
  668. *
  669. * Send FW initialize pattern for the function.
  670. *
  671. * return
  672. * Success: 0
  673. * Failure: Non-Zero value
  674. **/
  675. int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
  676. {
  677. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  678. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  679. int status;
  680. u8 *endian_check;
  681. spin_lock(&ctrl->mbox_lock);
  682. memset(wrb, 0, sizeof(*wrb));
  683. endian_check = (u8 *) wrb;
  684. *endian_check++ = 0xFF;
  685. *endian_check++ = 0x12;
  686. *endian_check++ = 0x34;
  687. *endian_check++ = 0xFF;
  688. *endian_check++ = 0xFF;
  689. *endian_check++ = 0x56;
  690. *endian_check++ = 0x78;
  691. *endian_check++ = 0xFF;
  692. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  693. status = be_mbox_notify(ctrl);
  694. if (status)
  695. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  696. "BC_%d : be_cmd_fw_initialize Failed\n");
  697. spin_unlock(&ctrl->mbox_lock);
  698. return status;
  699. }
  700. /**
  701. * be_cmd_fw_uninit()- Uinitialize FW
  702. * @ctrl: Pointer to function control structure
  703. *
  704. * Send FW uninitialize pattern for the function
  705. *
  706. * return
  707. * Success: 0
  708. * Failure: Non-Zero value
  709. **/
  710. int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
  711. {
  712. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  713. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  714. int status;
  715. u8 *endian_check;
  716. spin_lock(&ctrl->mbox_lock);
  717. memset(wrb, 0, sizeof(*wrb));
  718. endian_check = (u8 *) wrb;
  719. *endian_check++ = 0xFF;
  720. *endian_check++ = 0xAA;
  721. *endian_check++ = 0xBB;
  722. *endian_check++ = 0xFF;
  723. *endian_check++ = 0xFF;
  724. *endian_check++ = 0xCC;
  725. *endian_check++ = 0xDD;
  726. *endian_check = 0xFF;
  727. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  728. status = be_mbox_notify(ctrl);
  729. if (status)
  730. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  731. "BC_%d : be_cmd_fw_uninit Failed\n");
  732. spin_unlock(&ctrl->mbox_lock);
  733. return status;
  734. }
  735. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  736. struct be_queue_info *cq, struct be_queue_info *eq,
  737. bool sol_evts, bool no_delay, int coalesce_wm)
  738. {
  739. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  740. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  741. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  742. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  743. struct be_dma_mem *q_mem = &cq->dma_mem;
  744. void *ctxt = &req->context;
  745. int status;
  746. spin_lock(&ctrl->mbox_lock);
  747. memset(wrb, 0, sizeof(*wrb));
  748. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  749. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  750. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  751. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  752. if (is_chip_be2_be3r(phba)) {
  753. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  754. ctxt, coalesce_wm);
  755. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  756. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  757. __ilog2_u32(cq->len / 256));
  758. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  759. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  760. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  761. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  762. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  763. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  764. PCI_FUNC(ctrl->pdev->devfn));
  765. } else {
  766. req->hdr.version = MBX_CMD_VER2;
  767. req->page_size = 1;
  768. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  769. ctxt, coalesce_wm);
  770. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  771. ctxt, no_delay);
  772. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  773. __ilog2_u32(cq->len / 256));
  774. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  775. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  776. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  777. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  778. }
  779. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  780. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  781. status = be_mbox_notify(ctrl);
  782. if (!status) {
  783. cq->id = le16_to_cpu(resp->cq_id);
  784. cq->created = true;
  785. } else
  786. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  787. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  788. status);
  789. spin_unlock(&ctrl->mbox_lock);
  790. return status;
  791. }
  792. static u32 be_encoded_q_len(int q_len)
  793. {
  794. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  795. if (len_encoded == 16)
  796. len_encoded = 0;
  797. return len_encoded;
  798. }
  799. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  800. struct be_queue_info *mccq,
  801. struct be_queue_info *cq)
  802. {
  803. struct be_mcc_wrb *wrb;
  804. struct be_cmd_req_mcc_create *req;
  805. struct be_dma_mem *q_mem = &mccq->dma_mem;
  806. struct be_ctrl_info *ctrl;
  807. void *ctxt;
  808. int status;
  809. spin_lock(&phba->ctrl.mbox_lock);
  810. ctrl = &phba->ctrl;
  811. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  812. memset(wrb, 0, sizeof(*wrb));
  813. req = embedded_payload(wrb);
  814. ctxt = &req->context;
  815. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  816. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  817. OPCODE_COMMON_MCC_CREATE, sizeof(*req));
  818. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  819. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  820. PCI_FUNC(phba->pcidev->devfn));
  821. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  822. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  823. be_encoded_q_len(mccq->len));
  824. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  825. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  826. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  827. status = be_mbox_notify_wait(phba);
  828. if (!status) {
  829. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  830. mccq->id = le16_to_cpu(resp->id);
  831. mccq->created = true;
  832. }
  833. spin_unlock(&phba->ctrl.mbox_lock);
  834. return status;
  835. }
  836. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  837. int queue_type)
  838. {
  839. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  840. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  841. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  842. u8 subsys = 0, opcode = 0;
  843. int status;
  844. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  845. "BC_%d : In beiscsi_cmd_q_destroy "
  846. "queue_type : %d\n", queue_type);
  847. spin_lock(&ctrl->mbox_lock);
  848. memset(wrb, 0, sizeof(*wrb));
  849. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  850. switch (queue_type) {
  851. case QTYPE_EQ:
  852. subsys = CMD_SUBSYSTEM_COMMON;
  853. opcode = OPCODE_COMMON_EQ_DESTROY;
  854. break;
  855. case QTYPE_CQ:
  856. subsys = CMD_SUBSYSTEM_COMMON;
  857. opcode = OPCODE_COMMON_CQ_DESTROY;
  858. break;
  859. case QTYPE_MCCQ:
  860. subsys = CMD_SUBSYSTEM_COMMON;
  861. opcode = OPCODE_COMMON_MCC_DESTROY;
  862. break;
  863. case QTYPE_WRBQ:
  864. subsys = CMD_SUBSYSTEM_ISCSI;
  865. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  866. break;
  867. case QTYPE_DPDUQ:
  868. subsys = CMD_SUBSYSTEM_ISCSI;
  869. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  870. break;
  871. case QTYPE_SGL:
  872. subsys = CMD_SUBSYSTEM_ISCSI;
  873. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  874. break;
  875. default:
  876. spin_unlock(&ctrl->mbox_lock);
  877. BUG();
  878. return -ENXIO;
  879. }
  880. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  881. if (queue_type != QTYPE_SGL)
  882. req->id = cpu_to_le16(q->id);
  883. status = be_mbox_notify(ctrl);
  884. spin_unlock(&ctrl->mbox_lock);
  885. return status;
  886. }
  887. /**
  888. * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
  889. * @ctrl: ptr to ctrl_info
  890. * @cq: Completion Queue
  891. * @dq: Default Queue
  892. * @lenght: ring size
  893. * @entry_size: size of each entry in DEFQ
  894. * @is_header: Header or Data DEFQ
  895. * @ulp_num: Bind to which ULP
  896. *
  897. * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
  898. * on this queue by the FW
  899. *
  900. * return
  901. * Success: 0
  902. * Failure: Non-Zero Value
  903. *
  904. **/
  905. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  906. struct be_queue_info *cq,
  907. struct be_queue_info *dq, int length,
  908. int entry_size, uint8_t is_header,
  909. uint8_t ulp_num)
  910. {
  911. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  912. struct be_defq_create_req *req = embedded_payload(wrb);
  913. struct be_dma_mem *q_mem = &dq->dma_mem;
  914. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  915. void *ctxt = &req->context;
  916. int status;
  917. spin_lock(&ctrl->mbox_lock);
  918. memset(wrb, 0, sizeof(*wrb));
  919. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  920. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  921. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  922. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  923. if (phba->fw_config.dual_ulp_aware) {
  924. req->ulp_num = ulp_num;
  925. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  926. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  927. }
  928. if (is_chip_be2_be3r(phba)) {
  929. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  930. rx_pdid, ctxt, 0);
  931. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  932. rx_pdid_valid, ctxt, 1);
  933. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  934. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  935. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  936. ring_size, ctxt,
  937. be_encoded_q_len(length /
  938. sizeof(struct phys_addr)));
  939. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  940. default_buffer_size, ctxt, entry_size);
  941. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  942. cq_id_recv, ctxt, cq->id);
  943. } else {
  944. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  945. rx_pdid, ctxt, 0);
  946. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  947. rx_pdid_valid, ctxt, 1);
  948. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  949. ring_size, ctxt,
  950. be_encoded_q_len(length /
  951. sizeof(struct phys_addr)));
  952. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  953. default_buffer_size, ctxt, entry_size);
  954. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  955. cq_id_recv, ctxt, cq->id);
  956. }
  957. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  958. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  959. status = be_mbox_notify(ctrl);
  960. if (!status) {
  961. struct be_ring *defq_ring;
  962. struct be_defq_create_resp *resp = embedded_payload(wrb);
  963. dq->id = le16_to_cpu(resp->id);
  964. dq->created = true;
  965. if (is_header)
  966. defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
  967. else
  968. defq_ring = &phba->phwi_ctrlr->
  969. default_pdu_data[ulp_num];
  970. defq_ring->id = dq->id;
  971. if (!phba->fw_config.dual_ulp_aware) {
  972. defq_ring->ulp_num = BEISCSI_ULP0;
  973. defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
  974. } else {
  975. defq_ring->ulp_num = resp->ulp_num;
  976. defq_ring->doorbell_offset = resp->doorbell_offset;
  977. }
  978. }
  979. spin_unlock(&ctrl->mbox_lock);
  980. return status;
  981. }
  982. /**
  983. * be_cmd_wrbq_create()- Create WRBQ
  984. * @ctrl: ptr to ctrl_info
  985. * @q_mem: memory details for the queue
  986. * @wrbq: queue info
  987. * @pwrb_context: ptr to wrb_context
  988. * @ulp_num: ULP on which the WRBQ is to be created
  989. *
  990. * Create WRBQ on the passed ULP_NUM.
  991. *
  992. **/
  993. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
  994. struct be_dma_mem *q_mem,
  995. struct be_queue_info *wrbq,
  996. struct hwi_wrb_context *pwrb_context,
  997. uint8_t ulp_num)
  998. {
  999. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1000. struct be_wrbq_create_req *req = embedded_payload(wrb);
  1001. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  1002. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1003. int status;
  1004. spin_lock(&ctrl->mbox_lock);
  1005. memset(wrb, 0, sizeof(*wrb));
  1006. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1007. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1008. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  1009. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  1010. if (phba->fw_config.dual_ulp_aware) {
  1011. req->ulp_num = ulp_num;
  1012. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  1013. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  1014. }
  1015. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  1016. status = be_mbox_notify(ctrl);
  1017. if (!status) {
  1018. wrbq->id = le16_to_cpu(resp->cid);
  1019. wrbq->created = true;
  1020. pwrb_context->cid = wrbq->id;
  1021. if (!phba->fw_config.dual_ulp_aware) {
  1022. pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
  1023. pwrb_context->ulp_num = BEISCSI_ULP0;
  1024. } else {
  1025. pwrb_context->ulp_num = resp->ulp_num;
  1026. pwrb_context->doorbell_offset = resp->doorbell_offset;
  1027. }
  1028. }
  1029. spin_unlock(&ctrl->mbox_lock);
  1030. return status;
  1031. }
  1032. int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
  1033. struct be_dma_mem *q_mem)
  1034. {
  1035. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1036. struct be_post_template_pages_req *req = embedded_payload(wrb);
  1037. int status;
  1038. spin_lock(&ctrl->mbox_lock);
  1039. memset(wrb, 0, sizeof(*wrb));
  1040. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1041. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1042. OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
  1043. sizeof(*req));
  1044. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  1045. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1046. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  1047. status = be_mbox_notify(ctrl);
  1048. spin_unlock(&ctrl->mbox_lock);
  1049. return status;
  1050. }
  1051. int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
  1052. {
  1053. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1054. struct be_remove_template_pages_req *req = embedded_payload(wrb);
  1055. int status;
  1056. spin_lock(&ctrl->mbox_lock);
  1057. memset(wrb, 0, sizeof(*wrb));
  1058. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1059. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1060. OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
  1061. sizeof(*req));
  1062. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1063. status = be_mbox_notify(ctrl);
  1064. spin_unlock(&ctrl->mbox_lock);
  1065. return status;
  1066. }
  1067. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  1068. struct be_dma_mem *q_mem,
  1069. u32 page_offset, u32 num_pages)
  1070. {
  1071. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1072. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1073. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1074. int status;
  1075. unsigned int curr_pages;
  1076. u32 internal_page_offset = 0;
  1077. u32 temp_num_pages = num_pages;
  1078. if (num_pages == 0xff)
  1079. num_pages = 1;
  1080. spin_lock(&ctrl->mbox_lock);
  1081. do {
  1082. memset(wrb, 0, sizeof(*wrb));
  1083. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1084. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1085. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  1086. sizeof(*req));
  1087. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  1088. pages);
  1089. req->num_pages = min(num_pages, curr_pages);
  1090. req->page_offset = page_offset;
  1091. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  1092. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  1093. internal_page_offset += req->num_pages;
  1094. page_offset += req->num_pages;
  1095. num_pages -= req->num_pages;
  1096. if (temp_num_pages == 0xff)
  1097. req->num_pages = temp_num_pages;
  1098. status = be_mbox_notify(ctrl);
  1099. if (status) {
  1100. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1101. "BC_%d : FW CMD to map iscsi frags failed.\n");
  1102. goto error;
  1103. }
  1104. } while (num_pages > 0);
  1105. error:
  1106. spin_unlock(&ctrl->mbox_lock);
  1107. if (status != 0)
  1108. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  1109. return status;
  1110. }
  1111. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  1112. {
  1113. struct be_ctrl_info *ctrl = &phba->ctrl;
  1114. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1115. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1116. int status;
  1117. spin_lock(&ctrl->mbox_lock);
  1118. req = embedded_payload(wrb);
  1119. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1120. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1121. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1122. status = be_mbox_notify_wait(phba);
  1123. spin_unlock(&ctrl->mbox_lock);
  1124. return status;
  1125. }
  1126. /**
  1127. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1128. * @phba: device priv structure instance
  1129. * @vlan_tag: TAG to be set
  1130. *
  1131. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1132. *
  1133. * returns
  1134. * TAG for the MBX Cmd
  1135. * **/
  1136. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1137. uint16_t vlan_tag)
  1138. {
  1139. unsigned int tag = 0;
  1140. struct be_mcc_wrb *wrb;
  1141. struct be_cmd_set_vlan_req *req;
  1142. struct be_ctrl_info *ctrl = &phba->ctrl;
  1143. spin_lock(&ctrl->mbox_lock);
  1144. tag = alloc_mcc_tag(phba);
  1145. if (!tag) {
  1146. spin_unlock(&ctrl->mbox_lock);
  1147. return tag;
  1148. }
  1149. wrb = wrb_from_mccq(phba);
  1150. req = embedded_payload(wrb);
  1151. wrb->tag0 |= tag;
  1152. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1153. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1154. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1155. sizeof(*req));
  1156. req->interface_hndl = phba->interface_handle;
  1157. req->vlan_priority = vlan_tag;
  1158. be_mcc_notify(phba);
  1159. spin_unlock(&ctrl->mbox_lock);
  1160. return tag;
  1161. }