be_cmds.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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 (is_chip_be2_be3r(phba)) {
  744. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  745. ctxt, coalesce_wm);
  746. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  747. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  748. __ilog2_u32(cq->len / 256));
  749. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  750. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  751. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  752. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  753. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  754. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  755. PCI_FUNC(ctrl->pdev->devfn));
  756. } else {
  757. req->hdr.version = MBX_CMD_VER2;
  758. req->page_size = 1;
  759. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  760. ctxt, coalesce_wm);
  761. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  762. ctxt, no_delay);
  763. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  764. __ilog2_u32(cq->len / 256));
  765. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  766. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  767. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  768. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  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. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  887. void *ctxt = &req->context;
  888. int status;
  889. spin_lock(&ctrl->mbox_lock);
  890. memset(wrb, 0, sizeof(*wrb));
  891. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  892. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  893. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  894. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  895. if (is_chip_be2_be3r(phba)) {
  896. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  897. rx_pdid, ctxt, 0);
  898. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  899. rx_pdid_valid, ctxt, 1);
  900. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  901. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  902. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  903. ring_size, ctxt,
  904. be_encoded_q_len(length /
  905. sizeof(struct phys_addr)));
  906. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  907. default_buffer_size, ctxt, entry_size);
  908. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  909. cq_id_recv, ctxt, cq->id);
  910. } else {
  911. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  912. rx_pdid, ctxt, 0);
  913. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  914. rx_pdid_valid, ctxt, 1);
  915. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  916. ring_size, ctxt,
  917. be_encoded_q_len(length /
  918. sizeof(struct phys_addr)));
  919. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  920. default_buffer_size, ctxt, entry_size);
  921. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  922. cq_id_recv, ctxt, cq->id);
  923. }
  924. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  925. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  926. status = be_mbox_notify(ctrl);
  927. if (!status) {
  928. struct be_defq_create_resp *resp = embedded_payload(wrb);
  929. dq->id = le16_to_cpu(resp->id);
  930. dq->created = true;
  931. }
  932. spin_unlock(&ctrl->mbox_lock);
  933. return status;
  934. }
  935. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
  936. struct be_queue_info *wrbq)
  937. {
  938. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  939. struct be_wrbq_create_req *req = embedded_payload(wrb);
  940. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  941. int status;
  942. spin_lock(&ctrl->mbox_lock);
  943. memset(wrb, 0, sizeof(*wrb));
  944. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  945. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  946. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  947. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  948. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  949. status = be_mbox_notify(ctrl);
  950. if (!status) {
  951. wrbq->id = le16_to_cpu(resp->cid);
  952. wrbq->created = true;
  953. }
  954. spin_unlock(&ctrl->mbox_lock);
  955. return status;
  956. }
  957. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  958. struct be_dma_mem *q_mem,
  959. u32 page_offset, u32 num_pages)
  960. {
  961. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  962. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  963. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  964. int status;
  965. unsigned int curr_pages;
  966. u32 internal_page_offset = 0;
  967. u32 temp_num_pages = num_pages;
  968. if (num_pages == 0xff)
  969. num_pages = 1;
  970. spin_lock(&ctrl->mbox_lock);
  971. do {
  972. memset(wrb, 0, sizeof(*wrb));
  973. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  974. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  975. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  976. sizeof(*req));
  977. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  978. pages);
  979. req->num_pages = min(num_pages, curr_pages);
  980. req->page_offset = page_offset;
  981. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  982. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  983. internal_page_offset += req->num_pages;
  984. page_offset += req->num_pages;
  985. num_pages -= req->num_pages;
  986. if (temp_num_pages == 0xff)
  987. req->num_pages = temp_num_pages;
  988. status = be_mbox_notify(ctrl);
  989. if (status) {
  990. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  991. "BC_%d : FW CMD to map iscsi frags failed.\n");
  992. goto error;
  993. }
  994. } while (num_pages > 0);
  995. error:
  996. spin_unlock(&ctrl->mbox_lock);
  997. if (status != 0)
  998. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  999. return status;
  1000. }
  1001. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  1002. {
  1003. struct be_ctrl_info *ctrl = &phba->ctrl;
  1004. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1005. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1006. int status;
  1007. spin_lock(&ctrl->mbox_lock);
  1008. req = embedded_payload(wrb);
  1009. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1010. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1011. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1012. status = be_mbox_notify_wait(phba);
  1013. spin_unlock(&ctrl->mbox_lock);
  1014. return status;
  1015. }
  1016. /**
  1017. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1018. * @phba: device priv structure instance
  1019. * @vlan_tag: TAG to be set
  1020. *
  1021. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1022. *
  1023. * returns
  1024. * TAG for the MBX Cmd
  1025. * **/
  1026. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1027. uint16_t vlan_tag)
  1028. {
  1029. unsigned int tag = 0;
  1030. struct be_mcc_wrb *wrb;
  1031. struct be_cmd_set_vlan_req *req;
  1032. struct be_ctrl_info *ctrl = &phba->ctrl;
  1033. spin_lock(&ctrl->mbox_lock);
  1034. tag = alloc_mcc_tag(phba);
  1035. if (!tag) {
  1036. spin_unlock(&ctrl->mbox_lock);
  1037. return tag;
  1038. }
  1039. wrb = wrb_from_mccq(phba);
  1040. req = embedded_payload(wrb);
  1041. wrb->tag0 |= tag;
  1042. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1043. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1044. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1045. sizeof(*req));
  1046. req->interface_hndl = phba->interface_handle;
  1047. req->vlan_priority = vlan_tag;
  1048. be_mcc_notify(phba);
  1049. spin_unlock(&ctrl->mbox_lock);
  1050. return tag;
  1051. }