be_cmds.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /**
  2. * Copyright (C) 2005 - 2012 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.h"
  19. #include "be_mgmt.h"
  20. #include "be_main.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. goto release_mcc_tag;
  156. } else
  157. rc = 0;
  158. mcc_tag_response = phba->ctrl.mcc_numtag[tag];
  159. status = (mcc_tag_response & CQE_STATUS_MASK);
  160. addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
  161. CQE_STATUS_ADDL_SHIFT);
  162. if (cmd_hdr) {
  163. ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
  164. } else {
  165. wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
  166. CQE_STATUS_WRB_SHIFT;
  167. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  168. ioctl_hdr = embedded_payload(temp_wrb);
  169. if (wrb)
  170. *wrb = temp_wrb;
  171. }
  172. if (status || addl_status) {
  173. beiscsi_log(phba, KERN_ERR,
  174. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  175. BEISCSI_LOG_CONFIG,
  176. "BC_%d : MBX Cmd Failed for "
  177. "Subsys : %d Opcode : %d with "
  178. "Status : %d and Extd_Status : %d\n",
  179. ioctl_hdr->subsystem,
  180. ioctl_hdr->opcode,
  181. status, addl_status);
  182. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  183. ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
  184. if (ioctl_resp_hdr->response_length)
  185. goto release_mcc_tag;
  186. }
  187. rc = -EAGAIN;
  188. }
  189. release_mcc_tag:
  190. /* Release the MCC entry */
  191. free_mcc_tag(&phba->ctrl, tag);
  192. return rc;
  193. }
  194. void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
  195. {
  196. spin_lock(&ctrl->mbox_lock);
  197. tag = tag & 0x000000FF;
  198. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  199. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  200. ctrl->mcc_free_index = 0;
  201. else
  202. ctrl->mcc_free_index++;
  203. ctrl->mcc_tag_available++;
  204. spin_unlock(&ctrl->mbox_lock);
  205. }
  206. bool is_link_state_evt(u32 trailer)
  207. {
  208. return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
  209. ASYNC_TRAILER_EVENT_CODE_MASK) ==
  210. ASYNC_EVENT_CODE_LINK_STATE);
  211. }
  212. static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
  213. {
  214. if (compl->flags != 0) {
  215. compl->flags = le32_to_cpu(compl->flags);
  216. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  217. return true;
  218. } else
  219. return false;
  220. }
  221. static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
  222. {
  223. compl->flags = 0;
  224. }
  225. /*
  226. * be_mcc_compl_process()- Check the MBX comapletion status
  227. * @ctrl: Function specific MBX data structure
  228. * @compl: Completion status of MBX Command
  229. *
  230. * Check for the MBX completion status when BMBX method used
  231. *
  232. * return
  233. * Success: Zero
  234. * Failure: Non-Zero
  235. **/
  236. static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
  237. struct be_mcc_compl *compl)
  238. {
  239. u16 compl_status, extd_status;
  240. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  241. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  242. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  243. struct be_cmd_resp_hdr *resp_hdr;
  244. be_dws_le_to_cpu(compl, 4);
  245. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  246. CQE_STATUS_COMPL_MASK;
  247. if (compl_status != MCC_STATUS_SUCCESS) {
  248. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  249. CQE_STATUS_EXTD_MASK;
  250. beiscsi_log(phba, KERN_ERR,
  251. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  252. "BC_%d : error in cmd completion: "
  253. "Subsystem : %d Opcode : %d "
  254. "status(compl/extd)=%d/%d\n",
  255. hdr->subsystem, hdr->opcode,
  256. compl_status, extd_status);
  257. if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  258. resp_hdr = (struct be_cmd_resp_hdr *) hdr;
  259. if (resp_hdr->response_length)
  260. return 0;
  261. }
  262. return -EBUSY;
  263. }
  264. return 0;
  265. }
  266. int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
  267. struct be_mcc_compl *compl)
  268. {
  269. u16 compl_status, extd_status;
  270. unsigned short tag;
  271. be_dws_le_to_cpu(compl, 4);
  272. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  273. CQE_STATUS_COMPL_MASK;
  274. /* The ctrl.mcc_numtag[tag] is filled with
  275. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  276. * [7:0] = compl_status
  277. */
  278. tag = (compl->tag0 & 0x000000FF);
  279. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  280. CQE_STATUS_EXTD_MASK;
  281. ctrl->mcc_numtag[tag] = 0x80000000;
  282. ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
  283. ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
  284. ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
  285. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  286. return 0;
  287. }
  288. static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
  289. {
  290. struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
  291. struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
  292. if (be_mcc_compl_is_new(compl)) {
  293. queue_tail_inc(mcc_cq);
  294. return compl;
  295. }
  296. return NULL;
  297. }
  298. static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
  299. {
  300. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  301. }
  302. void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
  303. struct be_async_event_link_state *evt)
  304. {
  305. switch (evt->port_link_status) {
  306. case ASYNC_EVENT_LINK_DOWN:
  307. beiscsi_log(phba, KERN_ERR,
  308. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  309. "BC_%d : Link Down on Physical Port %d\n",
  310. evt->physical_port);
  311. phba->state |= BE_ADAPTER_LINK_DOWN;
  312. iscsi_host_for_each_session(phba->shost,
  313. be2iscsi_fail_session);
  314. break;
  315. case ASYNC_EVENT_LINK_UP:
  316. phba->state = BE_ADAPTER_UP;
  317. beiscsi_log(phba, KERN_ERR,
  318. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  319. "BC_%d : Link UP on Physical Port %d\n",
  320. evt->physical_port);
  321. break;
  322. default:
  323. beiscsi_log(phba, KERN_ERR,
  324. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  325. "BC_%d : Unexpected Async Notification %d on"
  326. "Physical Port %d\n",
  327. evt->port_link_status,
  328. evt->physical_port);
  329. }
  330. }
  331. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  332. u16 num_popped)
  333. {
  334. u32 val = 0;
  335. val |= qid & DB_CQ_RING_ID_MASK;
  336. if (arm)
  337. val |= 1 << DB_CQ_REARM_SHIFT;
  338. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  339. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  340. }
  341. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  342. {
  343. struct be_mcc_compl *compl;
  344. int num = 0, status = 0;
  345. struct be_ctrl_info *ctrl = &phba->ctrl;
  346. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  347. while ((compl = be_mcc_compl_get(phba))) {
  348. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  349. /* Interpret flags as an async trailer */
  350. if (is_link_state_evt(compl->flags))
  351. /* Interpret compl as a async link evt */
  352. beiscsi_async_link_state_process(phba,
  353. (struct be_async_event_link_state *) compl);
  354. else
  355. beiscsi_log(phba, KERN_ERR,
  356. BEISCSI_LOG_CONFIG |
  357. BEISCSI_LOG_MBOX,
  358. "BC_%d : Unsupported Async Event, flags"
  359. " = 0x%08x\n", compl->flags);
  360. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  361. status = be_mcc_compl_process(ctrl, compl);
  362. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  363. }
  364. be_mcc_compl_use(compl);
  365. num++;
  366. }
  367. if (num)
  368. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  369. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  370. return status;
  371. }
  372. /*
  373. * be_mcc_wait_compl()- Wait for MBX completion
  374. * @phba: driver private structure
  375. *
  376. * Wait till no more pending mcc requests are present
  377. *
  378. * return
  379. * Success: 0
  380. * Failure: Non-Zero
  381. *
  382. **/
  383. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  384. {
  385. int i, status;
  386. for (i = 0; i < mcc_timeout; i++) {
  387. if (beiscsi_error(phba))
  388. return -EIO;
  389. status = beiscsi_process_mcc(phba);
  390. if (status)
  391. return status;
  392. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  393. break;
  394. udelay(100);
  395. }
  396. if (i == mcc_timeout) {
  397. beiscsi_log(phba, KERN_ERR,
  398. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  399. "BC_%d : FW Timed Out\n");
  400. phba->fw_timeout = true;
  401. beiscsi_ue_detect(phba);
  402. return -EBUSY;
  403. }
  404. return 0;
  405. }
  406. /*
  407. * be_mcc_notify_wait()- Notify and wait for Compl
  408. * @phba: driver private structure
  409. *
  410. * Notify MCC requests and wait for completion
  411. *
  412. * return
  413. * Success: 0
  414. * Failure: Non-Zero
  415. **/
  416. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  417. {
  418. be_mcc_notify(phba);
  419. return be_mcc_wait_compl(phba);
  420. }
  421. /*
  422. * be_mbox_db_ready_wait()- Check ready status
  423. * @ctrl: Function specific MBX data structure
  424. *
  425. * Check for the ready status of FW to send BMBX
  426. * commands to adapter.
  427. *
  428. * return
  429. * Success: 0
  430. * Failure: Non-Zero
  431. **/
  432. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  433. {
  434. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  435. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  436. uint32_t wait = 0;
  437. u32 ready;
  438. do {
  439. if (beiscsi_error(phba))
  440. return -EIO;
  441. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  442. if (ready)
  443. break;
  444. if (wait > BEISCSI_HOST_MBX_TIMEOUT) {
  445. beiscsi_log(phba, KERN_ERR,
  446. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  447. "BC_%d : FW Timed Out\n");
  448. phba->fw_timeout = true;
  449. beiscsi_ue_detect(phba);
  450. return -EBUSY;
  451. }
  452. mdelay(1);
  453. wait++;
  454. } while (true);
  455. return 0;
  456. }
  457. /*
  458. * be_mbox_notify: Notify adapter of new BMBX command
  459. * @ctrl: Function specific MBX data structure
  460. *
  461. * Ring doorbell to inform adapter of a BMBX command
  462. * to process
  463. *
  464. * return
  465. * Success: 0
  466. * Failure: Non-Zero
  467. **/
  468. int be_mbox_notify(struct be_ctrl_info *ctrl)
  469. {
  470. int status;
  471. u32 val = 0;
  472. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  473. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  474. struct be_mcc_mailbox *mbox = mbox_mem->va;
  475. struct be_mcc_compl *compl = &mbox->compl;
  476. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  477. status = be_mbox_db_ready_wait(ctrl);
  478. if (status)
  479. return status;
  480. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  481. val |= MPU_MAILBOX_DB_HI_MASK;
  482. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  483. iowrite32(val, db);
  484. status = be_mbox_db_ready_wait(ctrl);
  485. if (status)
  486. return status;
  487. val = 0;
  488. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  489. val &= ~MPU_MAILBOX_DB_HI_MASK;
  490. val |= (u32) (mbox_mem->dma >> 4) << 2;
  491. iowrite32(val, db);
  492. status = be_mbox_db_ready_wait(ctrl);
  493. if (status)
  494. return status;
  495. if (be_mcc_compl_is_new(compl)) {
  496. status = be_mcc_compl_process(ctrl, &mbox->compl);
  497. be_mcc_compl_use(compl);
  498. if (status) {
  499. beiscsi_log(phba, KERN_ERR,
  500. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  501. "BC_%d : After be_mcc_compl_process\n");
  502. return status;
  503. }
  504. } else {
  505. beiscsi_log(phba, KERN_ERR,
  506. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  507. "BC_%d : Invalid Mailbox Completion\n");
  508. return -EBUSY;
  509. }
  510. return 0;
  511. }
  512. /*
  513. * Insert the mailbox address into the doorbell in two steps
  514. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  515. */
  516. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  517. {
  518. int status;
  519. u32 val = 0;
  520. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  521. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  522. struct be_mcc_mailbox *mbox = mbox_mem->va;
  523. struct be_mcc_compl *compl = &mbox->compl;
  524. struct be_ctrl_info *ctrl = &phba->ctrl;
  525. status = be_mbox_db_ready_wait(ctrl);
  526. if (status)
  527. return status;
  528. val |= MPU_MAILBOX_DB_HI_MASK;
  529. /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
  530. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  531. iowrite32(val, db);
  532. /* wait for ready to be set */
  533. status = be_mbox_db_ready_wait(ctrl);
  534. if (status != 0)
  535. return status;
  536. val = 0;
  537. /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
  538. val |= (u32)(mbox_mem->dma >> 4) << 2;
  539. iowrite32(val, db);
  540. status = be_mbox_db_ready_wait(ctrl);
  541. if (status != 0)
  542. return status;
  543. /* A cq entry has been made now */
  544. if (be_mcc_compl_is_new(compl)) {
  545. status = be_mcc_compl_process(ctrl, &mbox->compl);
  546. be_mcc_compl_use(compl);
  547. if (status)
  548. return status;
  549. } else {
  550. beiscsi_log(phba, KERN_ERR,
  551. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  552. "BC_%d : invalid mailbox completion\n");
  553. return -EBUSY;
  554. }
  555. return 0;
  556. }
  557. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  558. bool embedded, u8 sge_cnt)
  559. {
  560. if (embedded)
  561. wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
  562. else
  563. wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  564. MCC_WRB_SGE_CNT_SHIFT;
  565. wrb->payload_length = payload_len;
  566. be_dws_cpu_to_le(wrb, 8);
  567. }
  568. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  569. u8 subsystem, u8 opcode, int cmd_len)
  570. {
  571. req_hdr->opcode = opcode;
  572. req_hdr->subsystem = subsystem;
  573. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  574. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  575. }
  576. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  577. struct be_dma_mem *mem)
  578. {
  579. int i, buf_pages;
  580. u64 dma = (u64) mem->dma;
  581. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  582. for (i = 0; i < buf_pages; i++) {
  583. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  584. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  585. dma += PAGE_SIZE_4K;
  586. }
  587. }
  588. static u32 eq_delay_to_mult(u32 usec_delay)
  589. {
  590. #define MAX_INTR_RATE 651042
  591. const u32 round = 10;
  592. u32 multiplier;
  593. if (usec_delay == 0)
  594. multiplier = 0;
  595. else {
  596. u32 interrupt_rate = 1000000 / usec_delay;
  597. if (interrupt_rate == 0)
  598. multiplier = 1023;
  599. else {
  600. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  601. multiplier /= interrupt_rate;
  602. multiplier = (multiplier + round / 2) / round;
  603. multiplier = min(multiplier, (u32) 1023);
  604. }
  605. }
  606. return multiplier;
  607. }
  608. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  609. {
  610. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  611. }
  612. struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
  613. {
  614. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  615. struct be_mcc_wrb *wrb;
  616. BUG_ON(atomic_read(&mccq->used) >= mccq->len);
  617. wrb = queue_head_node(mccq);
  618. memset(wrb, 0, sizeof(*wrb));
  619. wrb->tag0 = (mccq->head & 0x000000FF) << 16;
  620. queue_head_inc(mccq);
  621. atomic_inc(&mccq->used);
  622. return wrb;
  623. }
  624. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  625. struct be_queue_info *eq, int eq_delay)
  626. {
  627. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  628. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  629. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  630. struct be_dma_mem *q_mem = &eq->dma_mem;
  631. int status;
  632. spin_lock(&ctrl->mbox_lock);
  633. memset(wrb, 0, sizeof(*wrb));
  634. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  635. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  636. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  637. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  638. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  639. PCI_FUNC(ctrl->pdev->devfn));
  640. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  641. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  642. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  643. __ilog2_u32(eq->len / 256));
  644. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  645. eq_delay_to_mult(eq_delay));
  646. be_dws_cpu_to_le(req->context, sizeof(req->context));
  647. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  648. status = be_mbox_notify(ctrl);
  649. if (!status) {
  650. eq->id = le16_to_cpu(resp->eq_id);
  651. eq->created = true;
  652. }
  653. spin_unlock(&ctrl->mbox_lock);
  654. return status;
  655. }
  656. /**
  657. * be_cmd_fw_initialize()- Initialize FW
  658. * @ctrl: Pointer to function control structure
  659. *
  660. * Send FW initialize pattern for the function.
  661. *
  662. * return
  663. * Success: 0
  664. * Failure: Non-Zero value
  665. **/
  666. int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
  667. {
  668. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  669. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  670. int status;
  671. u8 *endian_check;
  672. spin_lock(&ctrl->mbox_lock);
  673. memset(wrb, 0, sizeof(*wrb));
  674. endian_check = (u8 *) wrb;
  675. *endian_check++ = 0xFF;
  676. *endian_check++ = 0x12;
  677. *endian_check++ = 0x34;
  678. *endian_check++ = 0xFF;
  679. *endian_check++ = 0xFF;
  680. *endian_check++ = 0x56;
  681. *endian_check++ = 0x78;
  682. *endian_check++ = 0xFF;
  683. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  684. status = be_mbox_notify(ctrl);
  685. if (status)
  686. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  687. "BC_%d : be_cmd_fw_initialize Failed\n");
  688. spin_unlock(&ctrl->mbox_lock);
  689. return status;
  690. }
  691. /**
  692. * be_cmd_fw_uninit()- Uinitialize FW
  693. * @ctrl: Pointer to function control structure
  694. *
  695. * Send FW uninitialize pattern for the function
  696. *
  697. * return
  698. * Success: 0
  699. * Failure: Non-Zero value
  700. **/
  701. int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
  702. {
  703. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  704. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  705. int status;
  706. u8 *endian_check;
  707. spin_lock(&ctrl->mbox_lock);
  708. memset(wrb, 0, sizeof(*wrb));
  709. endian_check = (u8 *) wrb;
  710. *endian_check++ = 0xFF;
  711. *endian_check++ = 0xAA;
  712. *endian_check++ = 0xBB;
  713. *endian_check++ = 0xFF;
  714. *endian_check++ = 0xFF;
  715. *endian_check++ = 0xCC;
  716. *endian_check++ = 0xDD;
  717. *endian_check = 0xFF;
  718. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  719. status = be_mbox_notify(ctrl);
  720. if (status)
  721. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  722. "BC_%d : be_cmd_fw_uninit Failed\n");
  723. spin_unlock(&ctrl->mbox_lock);
  724. return status;
  725. }
  726. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  727. struct be_queue_info *cq, struct be_queue_info *eq,
  728. bool sol_evts, bool no_delay, int coalesce_wm)
  729. {
  730. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  731. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  732. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  733. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  734. struct be_dma_mem *q_mem = &cq->dma_mem;
  735. void *ctxt = &req->context;
  736. int status;
  737. spin_lock(&ctrl->mbox_lock);
  738. memset(wrb, 0, sizeof(*wrb));
  739. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  740. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  741. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  742. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  743. if (chip_skh_r(ctrl->pdev)) {
  744. req->hdr.version = MBX_CMD_VER2;
  745. req->page_size = 1;
  746. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  747. ctxt, coalesce_wm);
  748. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  749. ctxt, no_delay);
  750. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  751. __ilog2_u32(cq->len / 256));
  752. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  753. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  754. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  755. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  756. } else {
  757. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  758. ctxt, coalesce_wm);
  759. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  760. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  761. __ilog2_u32(cq->len / 256));
  762. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  763. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  764. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  765. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  766. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  767. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  768. PCI_FUNC(ctrl->pdev->devfn));
  769. }
  770. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  771. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  772. status = be_mbox_notify(ctrl);
  773. if (!status) {
  774. cq->id = le16_to_cpu(resp->cq_id);
  775. cq->created = true;
  776. } else
  777. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  778. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  779. status);
  780. spin_unlock(&ctrl->mbox_lock);
  781. return status;
  782. }
  783. static u32 be_encoded_q_len(int q_len)
  784. {
  785. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  786. if (len_encoded == 16)
  787. len_encoded = 0;
  788. return len_encoded;
  789. }
  790. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  791. struct be_queue_info *mccq,
  792. struct be_queue_info *cq)
  793. {
  794. struct be_mcc_wrb *wrb;
  795. struct be_cmd_req_mcc_create *req;
  796. struct be_dma_mem *q_mem = &mccq->dma_mem;
  797. struct be_ctrl_info *ctrl;
  798. void *ctxt;
  799. int status;
  800. spin_lock(&phba->ctrl.mbox_lock);
  801. ctrl = &phba->ctrl;
  802. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  803. memset(wrb, 0, sizeof(*wrb));
  804. req = embedded_payload(wrb);
  805. ctxt = &req->context;
  806. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  807. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  808. OPCODE_COMMON_MCC_CREATE, sizeof(*req));
  809. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  810. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  811. PCI_FUNC(phba->pcidev->devfn));
  812. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  813. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  814. be_encoded_q_len(mccq->len));
  815. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  816. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  817. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  818. status = be_mbox_notify_wait(phba);
  819. if (!status) {
  820. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  821. mccq->id = le16_to_cpu(resp->id);
  822. mccq->created = true;
  823. }
  824. spin_unlock(&phba->ctrl.mbox_lock);
  825. return status;
  826. }
  827. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  828. int queue_type)
  829. {
  830. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  831. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  832. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  833. u8 subsys = 0, opcode = 0;
  834. int status;
  835. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  836. "BC_%d : In beiscsi_cmd_q_destroy "
  837. "queue_type : %d\n", queue_type);
  838. spin_lock(&ctrl->mbox_lock);
  839. memset(wrb, 0, sizeof(*wrb));
  840. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  841. switch (queue_type) {
  842. case QTYPE_EQ:
  843. subsys = CMD_SUBSYSTEM_COMMON;
  844. opcode = OPCODE_COMMON_EQ_DESTROY;
  845. break;
  846. case QTYPE_CQ:
  847. subsys = CMD_SUBSYSTEM_COMMON;
  848. opcode = OPCODE_COMMON_CQ_DESTROY;
  849. break;
  850. case QTYPE_MCCQ:
  851. subsys = CMD_SUBSYSTEM_COMMON;
  852. opcode = OPCODE_COMMON_MCC_DESTROY;
  853. break;
  854. case QTYPE_WRBQ:
  855. subsys = CMD_SUBSYSTEM_ISCSI;
  856. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  857. break;
  858. case QTYPE_DPDUQ:
  859. subsys = CMD_SUBSYSTEM_ISCSI;
  860. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  861. break;
  862. case QTYPE_SGL:
  863. subsys = CMD_SUBSYSTEM_ISCSI;
  864. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  865. break;
  866. default:
  867. spin_unlock(&ctrl->mbox_lock);
  868. BUG();
  869. return -ENXIO;
  870. }
  871. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  872. if (queue_type != QTYPE_SGL)
  873. req->id = cpu_to_le16(q->id);
  874. status = be_mbox_notify(ctrl);
  875. spin_unlock(&ctrl->mbox_lock);
  876. return status;
  877. }
  878. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  879. struct be_queue_info *cq,
  880. struct be_queue_info *dq, int length,
  881. int entry_size)
  882. {
  883. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  884. struct be_defq_create_req *req = embedded_payload(wrb);
  885. struct be_dma_mem *q_mem = &dq->dma_mem;
  886. void *ctxt = &req->context;
  887. int status;
  888. spin_lock(&ctrl->mbox_lock);
  889. memset(wrb, 0, sizeof(*wrb));
  890. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  891. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  892. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  893. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  894. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid, ctxt, 0);
  895. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid_valid, ctxt,
  896. 1);
  897. AMAP_SET_BITS(struct amap_be_default_pdu_context, pci_func_id, ctxt,
  898. PCI_FUNC(ctrl->pdev->devfn));
  899. AMAP_SET_BITS(struct amap_be_default_pdu_context, ring_size, ctxt,
  900. be_encoded_q_len(length / sizeof(struct phys_addr)));
  901. AMAP_SET_BITS(struct amap_be_default_pdu_context, default_buffer_size,
  902. ctxt, entry_size);
  903. AMAP_SET_BITS(struct amap_be_default_pdu_context, cq_id_recv, ctxt,
  904. cq->id);
  905. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  906. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  907. status = be_mbox_notify(ctrl);
  908. if (!status) {
  909. struct be_defq_create_resp *resp = embedded_payload(wrb);
  910. dq->id = le16_to_cpu(resp->id);
  911. dq->created = true;
  912. }
  913. spin_unlock(&ctrl->mbox_lock);
  914. return status;
  915. }
  916. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
  917. struct be_queue_info *wrbq)
  918. {
  919. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  920. struct be_wrbq_create_req *req = embedded_payload(wrb);
  921. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  922. int status;
  923. spin_lock(&ctrl->mbox_lock);
  924. memset(wrb, 0, sizeof(*wrb));
  925. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  926. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  927. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  928. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  929. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  930. status = be_mbox_notify(ctrl);
  931. if (!status) {
  932. wrbq->id = le16_to_cpu(resp->cid);
  933. wrbq->created = true;
  934. }
  935. spin_unlock(&ctrl->mbox_lock);
  936. return status;
  937. }
  938. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  939. struct be_dma_mem *q_mem,
  940. u32 page_offset, u32 num_pages)
  941. {
  942. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  943. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  944. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  945. int status;
  946. unsigned int curr_pages;
  947. u32 internal_page_offset = 0;
  948. u32 temp_num_pages = num_pages;
  949. if (num_pages == 0xff)
  950. num_pages = 1;
  951. spin_lock(&ctrl->mbox_lock);
  952. do {
  953. memset(wrb, 0, sizeof(*wrb));
  954. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  955. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  956. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  957. sizeof(*req));
  958. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  959. pages);
  960. req->num_pages = min(num_pages, curr_pages);
  961. req->page_offset = page_offset;
  962. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  963. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  964. internal_page_offset += req->num_pages;
  965. page_offset += req->num_pages;
  966. num_pages -= req->num_pages;
  967. if (temp_num_pages == 0xff)
  968. req->num_pages = temp_num_pages;
  969. status = be_mbox_notify(ctrl);
  970. if (status) {
  971. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  972. "BC_%d : FW CMD to map iscsi frags failed.\n");
  973. goto error;
  974. }
  975. } while (num_pages > 0);
  976. error:
  977. spin_unlock(&ctrl->mbox_lock);
  978. if (status != 0)
  979. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  980. return status;
  981. }
  982. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  983. {
  984. struct be_ctrl_info *ctrl = &phba->ctrl;
  985. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  986. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  987. int status;
  988. spin_lock(&ctrl->mbox_lock);
  989. req = embedded_payload(wrb);
  990. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  991. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  992. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  993. status = be_mbox_notify_wait(phba);
  994. spin_unlock(&ctrl->mbox_lock);
  995. return status;
  996. }
  997. /**
  998. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  999. * @phba: device priv structure instance
  1000. * @vlan_tag: TAG to be set
  1001. *
  1002. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1003. *
  1004. * returns
  1005. * TAG for the MBX Cmd
  1006. * **/
  1007. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1008. uint16_t vlan_tag)
  1009. {
  1010. unsigned int tag = 0;
  1011. struct be_mcc_wrb *wrb;
  1012. struct be_cmd_set_vlan_req *req;
  1013. struct be_ctrl_info *ctrl = &phba->ctrl;
  1014. spin_lock(&ctrl->mbox_lock);
  1015. tag = alloc_mcc_tag(phba);
  1016. if (!tag) {
  1017. spin_unlock(&ctrl->mbox_lock);
  1018. return tag;
  1019. }
  1020. wrb = wrb_from_mccq(phba);
  1021. req = embedded_payload(wrb);
  1022. wrb->tag0 |= tag;
  1023. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1024. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1025. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1026. sizeof(*req));
  1027. req->interface_hndl = phba->interface_handle;
  1028. req->vlan_priority = vlan_tag;
  1029. be_mcc_notify(phba);
  1030. spin_unlock(&ctrl->mbox_lock);
  1031. return tag;
  1032. }