be_cmds.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2017 Broadcom. All Rights Reserved.
  4. * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
  5. *
  6. * Contact Information:
  7. * [email protected]
  8. */
  9. #include <scsi/iscsi_proto.h>
  10. #include "be_main.h"
  11. #include "be.h"
  12. #include "be_mgmt.h"
  13. /* UE Status Low CSR */
  14. static const char * const desc_ue_status_low[] = {
  15. "CEV",
  16. "CTX",
  17. "DBUF",
  18. "ERX",
  19. "Host",
  20. "MPU",
  21. "NDMA",
  22. "PTC ",
  23. "RDMA ",
  24. "RXF ",
  25. "RXIPS ",
  26. "RXULP0 ",
  27. "RXULP1 ",
  28. "RXULP2 ",
  29. "TIM ",
  30. "TPOST ",
  31. "TPRE ",
  32. "TXIPS ",
  33. "TXULP0 ",
  34. "TXULP1 ",
  35. "UC ",
  36. "WDMA ",
  37. "TXULP2 ",
  38. "HOST1 ",
  39. "P0_OB_LINK ",
  40. "P1_OB_LINK ",
  41. "HOST_GPIO ",
  42. "MBOX ",
  43. "AXGMAC0",
  44. "AXGMAC1",
  45. "JTAG",
  46. "MPU_INTPEND"
  47. };
  48. /* UE Status High CSR */
  49. static const char * const desc_ue_status_hi[] = {
  50. "LPCMEMHOST",
  51. "MGMT_MAC",
  52. "PCS0ONLINE",
  53. "MPU_IRAM",
  54. "PCS1ONLINE",
  55. "PCTL0",
  56. "PCTL1",
  57. "PMEM",
  58. "RR",
  59. "TXPB",
  60. "RXPP",
  61. "XAUI",
  62. "TXP",
  63. "ARM",
  64. "IPC",
  65. "HOST2",
  66. "HOST3",
  67. "HOST4",
  68. "HOST5",
  69. "HOST6",
  70. "HOST7",
  71. "HOST8",
  72. "HOST9",
  73. "NETC",
  74. "Unknown",
  75. "Unknown",
  76. "Unknown",
  77. "Unknown",
  78. "Unknown",
  79. "Unknown",
  80. "Unknown",
  81. "Unknown"
  82. };
  83. struct be_mcc_wrb *alloc_mcc_wrb(struct beiscsi_hba *phba,
  84. unsigned int *ref_tag)
  85. {
  86. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  87. struct be_mcc_wrb *wrb = NULL;
  88. unsigned int tag;
  89. spin_lock(&phba->ctrl.mcc_lock);
  90. if (mccq->used == mccq->len) {
  91. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT |
  92. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  93. "BC_%d : MCC queue full: WRB used %u tag avail %u\n",
  94. mccq->used, phba->ctrl.mcc_tag_available);
  95. goto alloc_failed;
  96. }
  97. if (!phba->ctrl.mcc_tag_available)
  98. goto alloc_failed;
  99. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  100. if (!tag) {
  101. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT |
  102. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  103. "BC_%d : MCC tag 0 allocated: tag avail %u alloc index %u\n",
  104. phba->ctrl.mcc_tag_available,
  105. phba->ctrl.mcc_alloc_index);
  106. goto alloc_failed;
  107. }
  108. /* return this tag for further reference */
  109. *ref_tag = tag;
  110. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  111. phba->ctrl.mcc_tag_status[tag] = 0;
  112. phba->ctrl.ptag_state[tag].tag_state = 0;
  113. phba->ctrl.ptag_state[tag].cbfn = NULL;
  114. phba->ctrl.mcc_tag_available--;
  115. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  116. phba->ctrl.mcc_alloc_index = 0;
  117. else
  118. phba->ctrl.mcc_alloc_index++;
  119. wrb = queue_head_node(mccq);
  120. memset(wrb, 0, sizeof(*wrb));
  121. wrb->tag0 = tag;
  122. wrb->tag0 |= (mccq->head << MCC_Q_WRB_IDX_SHIFT) & MCC_Q_WRB_IDX_MASK;
  123. queue_head_inc(mccq);
  124. mccq->used++;
  125. alloc_failed:
  126. spin_unlock(&phba->ctrl.mcc_lock);
  127. return wrb;
  128. }
  129. void free_mcc_wrb(struct be_ctrl_info *ctrl, unsigned int tag)
  130. {
  131. struct be_queue_info *mccq = &ctrl->mcc_obj.q;
  132. spin_lock(&ctrl->mcc_lock);
  133. tag = tag & MCC_Q_CMD_TAG_MASK;
  134. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  135. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  136. ctrl->mcc_free_index = 0;
  137. else
  138. ctrl->mcc_free_index++;
  139. ctrl->mcc_tag_available++;
  140. mccq->used--;
  141. spin_unlock(&ctrl->mcc_lock);
  142. }
  143. /*
  144. * beiscsi_mcc_compl_status - Return the status of MCC completion
  145. * @phba: Driver private structure
  146. * @tag: Tag for the MBX Command
  147. * @wrb: the WRB used for the MBX Command
  148. * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
  149. *
  150. * return
  151. * Success: 0
  152. * Failure: Non-Zero
  153. */
  154. int __beiscsi_mcc_compl_status(struct beiscsi_hba *phba,
  155. unsigned int tag,
  156. struct be_mcc_wrb **wrb,
  157. struct be_dma_mem *mbx_cmd_mem)
  158. {
  159. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  160. uint16_t status = 0, addl_status = 0, wrb_num = 0;
  161. struct be_cmd_resp_hdr *mbx_resp_hdr;
  162. struct be_cmd_req_hdr *mbx_hdr;
  163. struct be_mcc_wrb *temp_wrb;
  164. uint32_t mcc_tag_status;
  165. int rc = 0;
  166. mcc_tag_status = phba->ctrl.mcc_tag_status[tag];
  167. status = (mcc_tag_status & CQE_STATUS_MASK);
  168. addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >>
  169. CQE_STATUS_ADDL_SHIFT);
  170. if (mbx_cmd_mem) {
  171. mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va;
  172. } else {
  173. wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >>
  174. CQE_STATUS_WRB_SHIFT;
  175. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  176. mbx_hdr = embedded_payload(temp_wrb);
  177. if (wrb)
  178. *wrb = temp_wrb;
  179. }
  180. if (status || addl_status) {
  181. beiscsi_log(phba, KERN_WARNING,
  182. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  183. BEISCSI_LOG_CONFIG,
  184. "BC_%d : MBX Cmd Failed for Subsys : %d Opcode : %d with Status : %d and Extd_Status : %d\n",
  185. mbx_hdr->subsystem, mbx_hdr->opcode,
  186. status, addl_status);
  187. rc = -EIO;
  188. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  189. mbx_resp_hdr = (struct be_cmd_resp_hdr *)mbx_hdr;
  190. beiscsi_log(phba, KERN_WARNING,
  191. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  192. BEISCSI_LOG_CONFIG,
  193. "BC_%d : Insufficient Buffer Error Resp_Len : %d Actual_Resp_Len : %d\n",
  194. mbx_resp_hdr->response_length,
  195. mbx_resp_hdr->actual_resp_len);
  196. rc = -EAGAIN;
  197. }
  198. }
  199. return rc;
  200. }
  201. /*
  202. * beiscsi_mccq_compl_wait()- Process completion in MCC CQ
  203. * @phba: Driver private structure
  204. * @tag: Tag for the MBX Command
  205. * @wrb: the WRB used for the MBX Command
  206. * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
  207. *
  208. * Waits for MBX completion with the passed TAG.
  209. *
  210. * return
  211. * Success: 0
  212. * Failure: Non-Zero
  213. **/
  214. int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba,
  215. unsigned int tag,
  216. struct be_mcc_wrb **wrb,
  217. struct be_dma_mem *mbx_cmd_mem)
  218. {
  219. int rc = 0;
  220. if (!tag || tag > MAX_MCC_CMD) {
  221. __beiscsi_log(phba, KERN_ERR,
  222. "BC_%d : invalid tag %u\n", tag);
  223. return -EINVAL;
  224. }
  225. if (beiscsi_hba_in_error(phba)) {
  226. clear_bit(MCC_TAG_STATE_RUNNING,
  227. &phba->ctrl.ptag_state[tag].tag_state);
  228. return -EIO;
  229. }
  230. /* wait for the mccq completion */
  231. rc = wait_event_interruptible_timeout(phba->ctrl.mcc_wait[tag],
  232. phba->ctrl.mcc_tag_status[tag],
  233. msecs_to_jiffies(
  234. BEISCSI_HOST_MBX_TIMEOUT));
  235. /**
  236. * Return EIO if port is being disabled. Associated DMA memory, if any,
  237. * is freed by the caller. When port goes offline, MCCQ is cleaned up
  238. * so does WRB.
  239. */
  240. if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
  241. clear_bit(MCC_TAG_STATE_RUNNING,
  242. &phba->ctrl.ptag_state[tag].tag_state);
  243. return -EIO;
  244. }
  245. /**
  246. * If MBOX cmd timeout expired, tag and resource allocated
  247. * for cmd is not freed until FW returns completion.
  248. */
  249. if (rc <= 0) {
  250. struct be_dma_mem *tag_mem;
  251. /**
  252. * PCI/DMA memory allocated and posted in non-embedded mode
  253. * will have mbx_cmd_mem != NULL.
  254. * Save virtual and bus addresses for the command so that it
  255. * can be freed later.
  256. **/
  257. tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
  258. if (mbx_cmd_mem) {
  259. tag_mem->size = mbx_cmd_mem->size;
  260. tag_mem->va = mbx_cmd_mem->va;
  261. tag_mem->dma = mbx_cmd_mem->dma;
  262. } else
  263. tag_mem->size = 0;
  264. /* first make tag_mem_state visible to all */
  265. wmb();
  266. set_bit(MCC_TAG_STATE_TIMEOUT,
  267. &phba->ctrl.ptag_state[tag].tag_state);
  268. beiscsi_log(phba, KERN_ERR,
  269. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  270. BEISCSI_LOG_CONFIG,
  271. "BC_%d : MBX Cmd Completion timed out\n");
  272. return -EBUSY;
  273. }
  274. rc = __beiscsi_mcc_compl_status(phba, tag, wrb, mbx_cmd_mem);
  275. free_mcc_wrb(&phba->ctrl, tag);
  276. return rc;
  277. }
  278. /*
  279. * beiscsi_process_mbox_compl()- Check the MBX completion status
  280. * @ctrl: Function specific MBX data structure
  281. * @compl: Completion status of MBX Command
  282. *
  283. * Check for the MBX completion status when BMBX method used
  284. *
  285. * return
  286. * Success: Zero
  287. * Failure: Non-Zero
  288. **/
  289. static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl,
  290. struct be_mcc_compl *compl)
  291. {
  292. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  293. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  294. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  295. u16 compl_status, extd_status;
  296. /**
  297. * To check if valid bit is set, check the entire word as we don't know
  298. * the endianness of the data (old entry is host endian while a new
  299. * entry is little endian)
  300. */
  301. if (!compl->flags) {
  302. beiscsi_log(phba, KERN_ERR,
  303. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  304. "BC_%d : BMBX busy, no completion\n");
  305. return -EBUSY;
  306. }
  307. compl->flags = le32_to_cpu(compl->flags);
  308. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  309. /**
  310. * Just swap the status to host endian;
  311. * mcc tag is opaquely copied from mcc_wrb.
  312. */
  313. be_dws_le_to_cpu(compl, 4);
  314. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  315. CQE_STATUS_COMPL_MASK;
  316. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  317. CQE_STATUS_EXTD_MASK;
  318. /* Need to reset the entire word that houses the valid bit */
  319. compl->flags = 0;
  320. if (compl_status == MCC_STATUS_SUCCESS)
  321. return 0;
  322. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  323. "BC_%d : error in cmd completion: Subsystem : %d Opcode : %d status(compl/extd)=%d/%d\n",
  324. hdr->subsystem, hdr->opcode, compl_status, extd_status);
  325. return compl_status;
  326. }
  327. static void beiscsi_process_async_link(struct beiscsi_hba *phba,
  328. struct be_mcc_compl *compl)
  329. {
  330. struct be_async_event_link_state *evt;
  331. evt = (struct be_async_event_link_state *)compl;
  332. phba->port_speed = evt->port_speed;
  333. /**
  334. * Check logical link status in ASYNC event.
  335. * This has been newly introduced in SKH-R Firmware 10.0.338.45.
  336. **/
  337. if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) {
  338. set_bit(BEISCSI_HBA_LINK_UP, &phba->state);
  339. if (test_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state))
  340. beiscsi_start_boot_work(phba, BE_BOOT_INVALID_SHANDLE);
  341. __beiscsi_log(phba, KERN_ERR,
  342. "BC_%d : Link Up on Port %d tag 0x%x\n",
  343. evt->physical_port, evt->event_tag);
  344. } else {
  345. clear_bit(BEISCSI_HBA_LINK_UP, &phba->state);
  346. __beiscsi_log(phba, KERN_ERR,
  347. "BC_%d : Link Down on Port %d tag 0x%x\n",
  348. evt->physical_port, evt->event_tag);
  349. iscsi_host_for_each_session(phba->shost,
  350. beiscsi_session_fail);
  351. }
  352. }
  353. static char *beiscsi_port_misconf_event_msg[] = {
  354. "Physical Link is functional.",
  355. "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.",
  356. "Optics of two types installed - Remove one optic or install matching pair of optics.",
  357. "Incompatible optics - Replace with compatible optics for card to function.",
  358. "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.",
  359. "Uncertified optics - Replace with Avago Certified optics to enable link operation."
  360. };
  361. static void beiscsi_process_async_sli(struct beiscsi_hba *phba,
  362. struct be_mcc_compl *compl)
  363. {
  364. struct be_async_event_sli *async_sli;
  365. u8 evt_type, state, old_state, le;
  366. char *sev = KERN_WARNING;
  367. char *msg = NULL;
  368. evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT;
  369. evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK;
  370. /* processing only MISCONFIGURED physical port event */
  371. if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED)
  372. return;
  373. async_sli = (struct be_async_event_sli *)compl;
  374. state = async_sli->event_data1 >>
  375. (phba->fw_config.phys_port * 8) & 0xff;
  376. le = async_sli->event_data2 >>
  377. (phba->fw_config.phys_port * 8) & 0xff;
  378. old_state = phba->optic_state;
  379. phba->optic_state = state;
  380. if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) {
  381. /* fw is reporting a state we don't know, log and return */
  382. __beiscsi_log(phba, KERN_ERR,
  383. "BC_%d : Port %c: Unrecognized optic state 0x%x\n",
  384. phba->port_name, async_sli->event_data1);
  385. return;
  386. }
  387. if (ASYNC_SLI_LINK_EFFECT_VALID(le)) {
  388. /* log link effect for unqualified-4, uncertified-5 optics */
  389. if (state > 3)
  390. msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ?
  391. " Link is non-operational." :
  392. " Link is operational.";
  393. /* 1 - info */
  394. if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1)
  395. sev = KERN_INFO;
  396. /* 2 - error */
  397. if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2)
  398. sev = KERN_ERR;
  399. }
  400. if (old_state != phba->optic_state)
  401. __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n",
  402. phba->port_name,
  403. beiscsi_port_misconf_event_msg[state],
  404. !msg ? "" : msg);
  405. }
  406. void beiscsi_process_async_event(struct beiscsi_hba *phba,
  407. struct be_mcc_compl *compl)
  408. {
  409. char *sev = KERN_INFO;
  410. u8 evt_code;
  411. /* interpret flags as an async trailer */
  412. evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT;
  413. evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK;
  414. switch (evt_code) {
  415. case ASYNC_EVENT_CODE_LINK_STATE:
  416. beiscsi_process_async_link(phba, compl);
  417. break;
  418. case ASYNC_EVENT_CODE_ISCSI:
  419. if (test_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state))
  420. beiscsi_start_boot_work(phba, BE_BOOT_INVALID_SHANDLE);
  421. sev = KERN_ERR;
  422. break;
  423. case ASYNC_EVENT_CODE_SLI:
  424. beiscsi_process_async_sli(phba, compl);
  425. break;
  426. default:
  427. /* event not registered */
  428. sev = KERN_ERR;
  429. }
  430. beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  431. "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n",
  432. evt_code, compl->status, compl->flags);
  433. }
  434. int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
  435. struct be_mcc_compl *compl)
  436. {
  437. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  438. u16 compl_status, extd_status;
  439. struct be_dma_mem *tag_mem;
  440. unsigned int tag, wrb_idx;
  441. be_dws_le_to_cpu(compl, 4);
  442. tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK);
  443. wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT;
  444. if (!test_bit(MCC_TAG_STATE_RUNNING,
  445. &ctrl->ptag_state[tag].tag_state)) {
  446. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX |
  447. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  448. "BC_%d : MBX cmd completed but not posted\n");
  449. return 0;
  450. }
  451. /* end MCC with this tag */
  452. clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state);
  453. if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) {
  454. beiscsi_log(phba, KERN_WARNING,
  455. BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
  456. BEISCSI_LOG_CONFIG,
  457. "BC_%d : MBX Completion for timeout Command from FW\n");
  458. /**
  459. * Check for the size before freeing resource.
  460. * Only for non-embedded cmd, PCI resource is allocated.
  461. **/
  462. tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
  463. if (tag_mem->size) {
  464. dma_free_coherent(&ctrl->pdev->dev, tag_mem->size,
  465. tag_mem->va, tag_mem->dma);
  466. tag_mem->size = 0;
  467. }
  468. free_mcc_wrb(ctrl, tag);
  469. return 0;
  470. }
  471. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  472. CQE_STATUS_COMPL_MASK;
  473. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  474. CQE_STATUS_EXTD_MASK;
  475. /* The ctrl.mcc_tag_status[tag] is filled with
  476. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  477. * [7:0] = compl_status
  478. */
  479. ctrl->mcc_tag_status[tag] = CQE_VALID_MASK;
  480. ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT);
  481. ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) &
  482. CQE_STATUS_ADDL_MASK;
  483. ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK);
  484. if (test_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state)) {
  485. if (ctrl->ptag_state[tag].cbfn)
  486. ctrl->ptag_state[tag].cbfn(phba, tag);
  487. else
  488. __beiscsi_log(phba, KERN_ERR,
  489. "BC_%d : MBX ASYNC command with no callback\n");
  490. free_mcc_wrb(ctrl, tag);
  491. return 0;
  492. }
  493. if (test_bit(MCC_TAG_STATE_IGNORE, &ctrl->ptag_state[tag].tag_state)) {
  494. /* just check completion status and free wrb */
  495. __beiscsi_mcc_compl_status(phba, tag, NULL, NULL);
  496. free_mcc_wrb(ctrl, tag);
  497. return 0;
  498. }
  499. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  500. return 0;
  501. }
  502. void be_mcc_notify(struct beiscsi_hba *phba, unsigned int tag)
  503. {
  504. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  505. u32 val = 0;
  506. set_bit(MCC_TAG_STATE_RUNNING, &phba->ctrl.ptag_state[tag].tag_state);
  507. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  508. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  509. /* make request available for DMA */
  510. wmb();
  511. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  512. }
  513. /*
  514. * be_mbox_db_ready_poll()- Check ready status
  515. * @ctrl: Function specific MBX data structure
  516. *
  517. * Check for the ready status of FW to send BMBX
  518. * commands to adapter.
  519. *
  520. * return
  521. * Success: 0
  522. * Failure: Non-Zero
  523. **/
  524. static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl)
  525. {
  526. /* wait 30s for generic non-flash MBOX operation */
  527. #define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
  528. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  529. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  530. unsigned long timeout;
  531. u32 ready;
  532. /*
  533. * This BMBX busy wait path is used during init only.
  534. * For the commands executed during init, 5s should suffice.
  535. */
  536. timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
  537. do {
  538. if (beiscsi_hba_in_error(phba))
  539. return -EIO;
  540. ready = ioread32(db);
  541. if (ready == 0xffffffff)
  542. return -EIO;
  543. ready &= MPU_MAILBOX_DB_RDY_MASK;
  544. if (ready)
  545. return 0;
  546. if (time_after(jiffies, timeout))
  547. break;
  548. /* 1ms sleep is enough in most cases */
  549. schedule_timeout_uninterruptible(msecs_to_jiffies(1));
  550. } while (!ready);
  551. beiscsi_log(phba, KERN_ERR,
  552. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  553. "BC_%d : FW Timed Out\n");
  554. set_bit(BEISCSI_HBA_FW_TIMEOUT, &phba->state);
  555. return -EBUSY;
  556. }
  557. /*
  558. * be_mbox_notify: Notify adapter of new BMBX command
  559. * @ctrl: Function specific MBX data structure
  560. *
  561. * Ring doorbell to inform adapter of a BMBX command
  562. * to process
  563. *
  564. * return
  565. * Success: 0
  566. * Failure: Non-Zero
  567. **/
  568. static int be_mbox_notify(struct be_ctrl_info *ctrl)
  569. {
  570. int status;
  571. u32 val = 0;
  572. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  573. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  574. struct be_mcc_mailbox *mbox = mbox_mem->va;
  575. status = be_mbox_db_ready_poll(ctrl);
  576. if (status)
  577. return status;
  578. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  579. val |= MPU_MAILBOX_DB_HI_MASK;
  580. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  581. iowrite32(val, db);
  582. status = be_mbox_db_ready_poll(ctrl);
  583. if (status)
  584. return status;
  585. val = 0;
  586. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  587. val &= ~MPU_MAILBOX_DB_HI_MASK;
  588. val |= (u32) (mbox_mem->dma >> 4) << 2;
  589. iowrite32(val, db);
  590. status = be_mbox_db_ready_poll(ctrl);
  591. if (status)
  592. return status;
  593. /* RDY is set; small delay before CQE read. */
  594. udelay(1);
  595. status = beiscsi_process_mbox_compl(ctrl, &mbox->compl);
  596. return status;
  597. }
  598. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, u32 payload_len,
  599. bool embedded, u8 sge_cnt)
  600. {
  601. if (embedded)
  602. wrb->emb_sgecnt_special |= MCC_WRB_EMBEDDED_MASK;
  603. else
  604. wrb->emb_sgecnt_special |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  605. MCC_WRB_SGE_CNT_SHIFT;
  606. wrb->payload_length = payload_len;
  607. be_dws_cpu_to_le(wrb, 8);
  608. }
  609. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  610. u8 subsystem, u8 opcode, u32 cmd_len)
  611. {
  612. req_hdr->opcode = opcode;
  613. req_hdr->subsystem = subsystem;
  614. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  615. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  616. }
  617. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  618. struct be_dma_mem *mem)
  619. {
  620. int i, buf_pages;
  621. u64 dma = (u64) mem->dma;
  622. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  623. for (i = 0; i < buf_pages; i++) {
  624. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  625. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  626. dma += PAGE_SIZE_4K;
  627. }
  628. }
  629. static u32 eq_delay_to_mult(u32 usec_delay)
  630. {
  631. #define MAX_INTR_RATE 651042
  632. const u32 round = 10;
  633. u32 multiplier;
  634. if (usec_delay == 0)
  635. multiplier = 0;
  636. else {
  637. u32 interrupt_rate = 1000000 / usec_delay;
  638. if (interrupt_rate == 0)
  639. multiplier = 1023;
  640. else {
  641. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  642. multiplier /= interrupt_rate;
  643. multiplier = (multiplier + round / 2) / round;
  644. multiplier = min(multiplier, (u32) 1023);
  645. }
  646. }
  647. return multiplier;
  648. }
  649. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  650. {
  651. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  652. }
  653. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  654. struct be_queue_info *eq, int eq_delay)
  655. {
  656. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  657. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  658. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  659. struct be_dma_mem *q_mem = &eq->dma_mem;
  660. int status;
  661. mutex_lock(&ctrl->mbox_lock);
  662. memset(wrb, 0, sizeof(*wrb));
  663. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  664. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  665. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  666. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  667. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  668. PCI_FUNC(ctrl->pdev->devfn));
  669. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  670. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  671. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  672. __ilog2_u32(eq->len / 256));
  673. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  674. eq_delay_to_mult(eq_delay));
  675. be_dws_cpu_to_le(req->context, sizeof(req->context));
  676. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  677. status = be_mbox_notify(ctrl);
  678. if (!status) {
  679. eq->id = le16_to_cpu(resp->eq_id);
  680. eq->created = true;
  681. }
  682. mutex_unlock(&ctrl->mbox_lock);
  683. return status;
  684. }
  685. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  686. struct be_queue_info *cq, struct be_queue_info *eq,
  687. bool sol_evts, bool no_delay, int coalesce_wm)
  688. {
  689. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  690. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  691. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  692. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  693. struct be_dma_mem *q_mem = &cq->dma_mem;
  694. void *ctxt = &req->context;
  695. int status;
  696. mutex_lock(&ctrl->mbox_lock);
  697. memset(wrb, 0, sizeof(*wrb));
  698. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  699. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  700. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  701. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  702. if (is_chip_be2_be3r(phba)) {
  703. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  704. ctxt, coalesce_wm);
  705. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  706. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  707. __ilog2_u32(cq->len / 256));
  708. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  709. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  710. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  711. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  712. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  713. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  714. PCI_FUNC(ctrl->pdev->devfn));
  715. } else {
  716. req->hdr.version = MBX_CMD_VER2;
  717. req->page_size = 1;
  718. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  719. ctxt, coalesce_wm);
  720. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  721. ctxt, no_delay);
  722. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  723. __ilog2_u32(cq->len / 256));
  724. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  725. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  726. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  727. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  728. }
  729. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  730. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  731. status = be_mbox_notify(ctrl);
  732. if (!status) {
  733. cq->id = le16_to_cpu(resp->cq_id);
  734. cq->created = true;
  735. } else
  736. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  737. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  738. status);
  739. mutex_unlock(&ctrl->mbox_lock);
  740. return status;
  741. }
  742. static u32 be_encoded_q_len(int q_len)
  743. {
  744. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  745. if (len_encoded == 16)
  746. len_encoded = 0;
  747. return len_encoded;
  748. }
  749. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  750. struct be_queue_info *mccq,
  751. struct be_queue_info *cq)
  752. {
  753. struct be_mcc_wrb *wrb;
  754. struct be_cmd_req_mcc_create_ext *req;
  755. struct be_dma_mem *q_mem = &mccq->dma_mem;
  756. struct be_ctrl_info *ctrl;
  757. void *ctxt;
  758. int status;
  759. mutex_lock(&phba->ctrl.mbox_lock);
  760. ctrl = &phba->ctrl;
  761. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  762. memset(wrb, 0, sizeof(*wrb));
  763. req = embedded_payload(wrb);
  764. ctxt = &req->context;
  765. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  766. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  767. OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
  768. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  769. req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
  770. req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
  771. req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
  772. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  773. PCI_FUNC(phba->pcidev->devfn));
  774. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  775. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  776. be_encoded_q_len(mccq->len));
  777. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  778. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  779. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  780. status = be_mbox_notify(ctrl);
  781. if (!status) {
  782. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  783. mccq->id = le16_to_cpu(resp->id);
  784. mccq->created = true;
  785. }
  786. mutex_unlock(&phba->ctrl.mbox_lock);
  787. return status;
  788. }
  789. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  790. int queue_type)
  791. {
  792. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  793. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  794. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  795. u8 subsys = 0, opcode = 0;
  796. int status;
  797. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  798. "BC_%d : In beiscsi_cmd_q_destroy "
  799. "queue_type : %d\n", queue_type);
  800. mutex_lock(&ctrl->mbox_lock);
  801. memset(wrb, 0, sizeof(*wrb));
  802. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  803. switch (queue_type) {
  804. case QTYPE_EQ:
  805. subsys = CMD_SUBSYSTEM_COMMON;
  806. opcode = OPCODE_COMMON_EQ_DESTROY;
  807. break;
  808. case QTYPE_CQ:
  809. subsys = CMD_SUBSYSTEM_COMMON;
  810. opcode = OPCODE_COMMON_CQ_DESTROY;
  811. break;
  812. case QTYPE_MCCQ:
  813. subsys = CMD_SUBSYSTEM_COMMON;
  814. opcode = OPCODE_COMMON_MCC_DESTROY;
  815. break;
  816. case QTYPE_WRBQ:
  817. subsys = CMD_SUBSYSTEM_ISCSI;
  818. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  819. break;
  820. case QTYPE_DPDUQ:
  821. subsys = CMD_SUBSYSTEM_ISCSI;
  822. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  823. break;
  824. case QTYPE_SGL:
  825. subsys = CMD_SUBSYSTEM_ISCSI;
  826. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  827. break;
  828. default:
  829. mutex_unlock(&ctrl->mbox_lock);
  830. BUG();
  831. }
  832. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  833. if (queue_type != QTYPE_SGL)
  834. req->id = cpu_to_le16(q->id);
  835. status = be_mbox_notify(ctrl);
  836. mutex_unlock(&ctrl->mbox_lock);
  837. return status;
  838. }
  839. /**
  840. * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
  841. * @ctrl: ptr to ctrl_info
  842. * @cq: Completion Queue
  843. * @dq: Default Queue
  844. * @length: ring size
  845. * @entry_size: size of each entry in DEFQ
  846. * @is_header: Header or Data DEFQ
  847. * @ulp_num: Bind to which ULP
  848. *
  849. * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
  850. * on this queue by the FW
  851. *
  852. * return
  853. * Success: 0
  854. * Failure: Non-Zero Value
  855. *
  856. **/
  857. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  858. struct be_queue_info *cq,
  859. struct be_queue_info *dq, int length,
  860. int entry_size, uint8_t is_header,
  861. uint8_t ulp_num)
  862. {
  863. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  864. struct be_defq_create_req *req = embedded_payload(wrb);
  865. struct be_dma_mem *q_mem = &dq->dma_mem;
  866. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  867. void *ctxt = &req->context;
  868. int status;
  869. mutex_lock(&ctrl->mbox_lock);
  870. memset(wrb, 0, sizeof(*wrb));
  871. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  872. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  873. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  874. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  875. if (phba->fw_config.dual_ulp_aware) {
  876. req->ulp_num = ulp_num;
  877. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  878. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  879. }
  880. if (is_chip_be2_be3r(phba)) {
  881. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  882. rx_pdid, ctxt, 0);
  883. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  884. rx_pdid_valid, ctxt, 1);
  885. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  886. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  887. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  888. ring_size, ctxt,
  889. be_encoded_q_len(length /
  890. sizeof(struct phys_addr)));
  891. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  892. default_buffer_size, ctxt, entry_size);
  893. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  894. cq_id_recv, ctxt, cq->id);
  895. } else {
  896. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  897. rx_pdid, ctxt, 0);
  898. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  899. rx_pdid_valid, ctxt, 1);
  900. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  901. ring_size, ctxt,
  902. be_encoded_q_len(length /
  903. sizeof(struct phys_addr)));
  904. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  905. default_buffer_size, ctxt, entry_size);
  906. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  907. cq_id_recv, ctxt, cq->id);
  908. }
  909. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  910. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  911. status = be_mbox_notify(ctrl);
  912. if (!status) {
  913. struct be_ring *defq_ring;
  914. struct be_defq_create_resp *resp = embedded_payload(wrb);
  915. dq->id = le16_to_cpu(resp->id);
  916. dq->created = true;
  917. if (is_header)
  918. defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
  919. else
  920. defq_ring = &phba->phwi_ctrlr->
  921. default_pdu_data[ulp_num];
  922. defq_ring->id = dq->id;
  923. if (!phba->fw_config.dual_ulp_aware) {
  924. defq_ring->ulp_num = BEISCSI_ULP0;
  925. defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
  926. } else {
  927. defq_ring->ulp_num = resp->ulp_num;
  928. defq_ring->doorbell_offset = resp->doorbell_offset;
  929. }
  930. }
  931. mutex_unlock(&ctrl->mbox_lock);
  932. return status;
  933. }
  934. /**
  935. * be_cmd_wrbq_create()- Create WRBQ
  936. * @ctrl: ptr to ctrl_info
  937. * @q_mem: memory details for the queue
  938. * @wrbq: queue info
  939. * @pwrb_context: ptr to wrb_context
  940. * @ulp_num: ULP on which the WRBQ is to be created
  941. *
  942. * Create WRBQ on the passed ULP_NUM.
  943. *
  944. **/
  945. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
  946. struct be_dma_mem *q_mem,
  947. struct be_queue_info *wrbq,
  948. struct hwi_wrb_context *pwrb_context,
  949. uint8_t ulp_num)
  950. {
  951. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  952. struct be_wrbq_create_req *req = embedded_payload(wrb);
  953. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  954. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  955. int status;
  956. mutex_lock(&ctrl->mbox_lock);
  957. memset(wrb, 0, sizeof(*wrb));
  958. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  959. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  960. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  961. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  962. if (phba->fw_config.dual_ulp_aware) {
  963. req->ulp_num = ulp_num;
  964. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  965. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  966. }
  967. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  968. status = be_mbox_notify(ctrl);
  969. if (!status) {
  970. wrbq->id = le16_to_cpu(resp->cid);
  971. wrbq->created = true;
  972. pwrb_context->cid = wrbq->id;
  973. if (!phba->fw_config.dual_ulp_aware) {
  974. pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
  975. pwrb_context->ulp_num = BEISCSI_ULP0;
  976. } else {
  977. pwrb_context->ulp_num = resp->ulp_num;
  978. pwrb_context->doorbell_offset = resp->doorbell_offset;
  979. }
  980. }
  981. mutex_unlock(&ctrl->mbox_lock);
  982. return status;
  983. }
  984. int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
  985. struct be_dma_mem *q_mem)
  986. {
  987. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  988. struct be_post_template_pages_req *req = embedded_payload(wrb);
  989. int status;
  990. mutex_lock(&ctrl->mbox_lock);
  991. memset(wrb, 0, sizeof(*wrb));
  992. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  993. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  994. OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
  995. sizeof(*req));
  996. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  997. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  998. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  999. status = be_mbox_notify(ctrl);
  1000. mutex_unlock(&ctrl->mbox_lock);
  1001. return status;
  1002. }
  1003. int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
  1004. {
  1005. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1006. struct be_remove_template_pages_req *req = embedded_payload(wrb);
  1007. int status;
  1008. mutex_lock(&ctrl->mbox_lock);
  1009. memset(wrb, 0, sizeof(*wrb));
  1010. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1011. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1012. OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
  1013. sizeof(*req));
  1014. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1015. status = be_mbox_notify(ctrl);
  1016. mutex_unlock(&ctrl->mbox_lock);
  1017. return status;
  1018. }
  1019. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  1020. struct be_dma_mem *q_mem,
  1021. u32 page_offset, u32 num_pages)
  1022. {
  1023. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1024. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1025. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1026. int status;
  1027. unsigned int curr_pages;
  1028. u32 internal_page_offset = 0;
  1029. u32 temp_num_pages = num_pages;
  1030. if (num_pages == 0xff)
  1031. num_pages = 1;
  1032. mutex_lock(&ctrl->mbox_lock);
  1033. do {
  1034. memset(wrb, 0, sizeof(*wrb));
  1035. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1036. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1037. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  1038. sizeof(*req));
  1039. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  1040. pages);
  1041. req->num_pages = min(num_pages, curr_pages);
  1042. req->page_offset = page_offset;
  1043. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  1044. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  1045. internal_page_offset += req->num_pages;
  1046. page_offset += req->num_pages;
  1047. num_pages -= req->num_pages;
  1048. if (temp_num_pages == 0xff)
  1049. req->num_pages = temp_num_pages;
  1050. status = be_mbox_notify(ctrl);
  1051. if (status) {
  1052. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1053. "BC_%d : FW CMD to map iscsi frags failed.\n");
  1054. goto error;
  1055. }
  1056. } while (num_pages > 0);
  1057. error:
  1058. mutex_unlock(&ctrl->mbox_lock);
  1059. if (status != 0)
  1060. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  1061. return status;
  1062. }
  1063. /**
  1064. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1065. * @phba: device priv structure instance
  1066. * @vlan_tag: TAG to be set
  1067. *
  1068. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1069. *
  1070. * returns
  1071. * TAG for the MBX Cmd
  1072. * **/
  1073. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1074. uint16_t vlan_tag)
  1075. {
  1076. unsigned int tag;
  1077. struct be_mcc_wrb *wrb;
  1078. struct be_cmd_set_vlan_req *req;
  1079. struct be_ctrl_info *ctrl = &phba->ctrl;
  1080. if (mutex_lock_interruptible(&ctrl->mbox_lock))
  1081. return 0;
  1082. wrb = alloc_mcc_wrb(phba, &tag);
  1083. if (!wrb) {
  1084. mutex_unlock(&ctrl->mbox_lock);
  1085. return 0;
  1086. }
  1087. req = embedded_payload(wrb);
  1088. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1089. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1090. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1091. sizeof(*req));
  1092. req->interface_hndl = phba->interface_handle;
  1093. req->vlan_priority = vlan_tag;
  1094. be_mcc_notify(phba, tag);
  1095. mutex_unlock(&ctrl->mbox_lock);
  1096. return tag;
  1097. }
  1098. int beiscsi_check_supported_fw(struct be_ctrl_info *ctrl,
  1099. struct beiscsi_hba *phba)
  1100. {
  1101. struct be_dma_mem nonemb_cmd;
  1102. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1103. struct be_mgmt_controller_attributes *req;
  1104. struct be_sge *sge = nonembedded_sgl(wrb);
  1105. int status = 0;
  1106. nonemb_cmd.va = dma_alloc_coherent(&ctrl->pdev->dev,
  1107. sizeof(struct be_mgmt_controller_attributes),
  1108. &nonemb_cmd.dma, GFP_KERNEL);
  1109. if (nonemb_cmd.va == NULL) {
  1110. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1111. "BG_%d : dma_alloc_coherent failed in %s\n",
  1112. __func__);
  1113. return -ENOMEM;
  1114. }
  1115. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  1116. req = nonemb_cmd.va;
  1117. memset(req, 0, sizeof(*req));
  1118. mutex_lock(&ctrl->mbox_lock);
  1119. memset(wrb, 0, sizeof(*wrb));
  1120. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  1121. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1122. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  1123. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  1124. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  1125. sge->len = cpu_to_le32(nonemb_cmd.size);
  1126. status = be_mbox_notify(ctrl);
  1127. if (!status) {
  1128. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  1129. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1130. "BG_%d : Firmware Version of CMD : %s\n"
  1131. "Firmware Version is : %s\n"
  1132. "Developer Build, not performing version check...\n",
  1133. resp->params.hba_attribs
  1134. .flashrom_version_string,
  1135. resp->params.hba_attribs.
  1136. firmware_version_string);
  1137. phba->fw_config.iscsi_features =
  1138. resp->params.hba_attribs.iscsi_features;
  1139. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1140. "BM_%d : phba->fw_config.iscsi_features = %d\n",
  1141. phba->fw_config.iscsi_features);
  1142. memcpy(phba->fw_ver_str, resp->params.hba_attribs.
  1143. firmware_version_string, BEISCSI_VER_STRLEN);
  1144. } else
  1145. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1146. "BG_%d : Failed in beiscsi_check_supported_fw\n");
  1147. mutex_unlock(&ctrl->mbox_lock);
  1148. if (nonemb_cmd.va)
  1149. dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd.size,
  1150. nonemb_cmd.va, nonemb_cmd.dma);
  1151. return status;
  1152. }
  1153. /**
  1154. * beiscsi_get_fw_config()- Get the FW config for the function
  1155. * @ctrl: ptr to Ctrl Info
  1156. * @phba: ptr to the dev priv structure
  1157. *
  1158. * Get the FW config and resources available for the function.
  1159. * The resources are created based on the count received here.
  1160. *
  1161. * return
  1162. * Success: 0
  1163. * Failure: Non-Zero Value
  1164. **/
  1165. int beiscsi_get_fw_config(struct be_ctrl_info *ctrl,
  1166. struct beiscsi_hba *phba)
  1167. {
  1168. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1169. struct be_fw_cfg *pfw_cfg = embedded_payload(wrb);
  1170. uint32_t cid_count, icd_count;
  1171. int status = -EINVAL;
  1172. uint8_t ulp_num = 0;
  1173. mutex_lock(&ctrl->mbox_lock);
  1174. memset(wrb, 0, sizeof(*wrb));
  1175. be_wrb_hdr_prepare(wrb, sizeof(*pfw_cfg), true, 0);
  1176. be_cmd_hdr_prepare(&pfw_cfg->hdr, CMD_SUBSYSTEM_COMMON,
  1177. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
  1178. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1179. if (be_mbox_notify(ctrl)) {
  1180. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1181. "BG_%d : Failed in beiscsi_get_fw_config\n");
  1182. goto fail_init;
  1183. }
  1184. /* FW response formats depend on port id */
  1185. phba->fw_config.phys_port = pfw_cfg->phys_port;
  1186. if (phba->fw_config.phys_port >= BEISCSI_PHYS_PORT_MAX) {
  1187. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1188. "BG_%d : invalid physical port id %d\n",
  1189. phba->fw_config.phys_port);
  1190. goto fail_init;
  1191. }
  1192. /* populate and check FW config against min and max values */
  1193. if (!is_chip_be2_be3r(phba)) {
  1194. phba->fw_config.eqid_count = pfw_cfg->eqid_count;
  1195. phba->fw_config.cqid_count = pfw_cfg->cqid_count;
  1196. if (phba->fw_config.eqid_count == 0 ||
  1197. phba->fw_config.eqid_count > 2048) {
  1198. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1199. "BG_%d : invalid EQ count %d\n",
  1200. phba->fw_config.eqid_count);
  1201. goto fail_init;
  1202. }
  1203. if (phba->fw_config.cqid_count == 0 ||
  1204. phba->fw_config.cqid_count > 4096) {
  1205. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1206. "BG_%d : invalid CQ count %d\n",
  1207. phba->fw_config.cqid_count);
  1208. goto fail_init;
  1209. }
  1210. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1211. "BG_%d : EQ_Count : %d CQ_Count : %d\n",
  1212. phba->fw_config.eqid_count,
  1213. phba->fw_config.cqid_count);
  1214. }
  1215. /**
  1216. * Check on which all ULP iSCSI Protocol is loaded.
  1217. * Set the Bit for those ULP. This set flag is used
  1218. * at all places in the code to check on which ULP
  1219. * iSCSi Protocol is loaded
  1220. **/
  1221. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  1222. if (pfw_cfg->ulp[ulp_num].ulp_mode &
  1223. BEISCSI_ULP_ISCSI_INI_MODE) {
  1224. set_bit(ulp_num, &phba->fw_config.ulp_supported);
  1225. /* Get the CID, ICD and Chain count for each ULP */
  1226. phba->fw_config.iscsi_cid_start[ulp_num] =
  1227. pfw_cfg->ulp[ulp_num].sq_base;
  1228. phba->fw_config.iscsi_cid_count[ulp_num] =
  1229. pfw_cfg->ulp[ulp_num].sq_count;
  1230. phba->fw_config.iscsi_icd_start[ulp_num] =
  1231. pfw_cfg->ulp[ulp_num].icd_base;
  1232. phba->fw_config.iscsi_icd_count[ulp_num] =
  1233. pfw_cfg->ulp[ulp_num].icd_count;
  1234. phba->fw_config.iscsi_chain_start[ulp_num] =
  1235. pfw_cfg->chain_icd[ulp_num].chain_base;
  1236. phba->fw_config.iscsi_chain_count[ulp_num] =
  1237. pfw_cfg->chain_icd[ulp_num].chain_count;
  1238. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1239. "BG_%d : Function loaded on ULP : %d\n"
  1240. "\tiscsi_cid_count : %d\n"
  1241. "\tiscsi_cid_start : %d\n"
  1242. "\t iscsi_icd_count : %d\n"
  1243. "\t iscsi_icd_start : %d\n",
  1244. ulp_num,
  1245. phba->fw_config.
  1246. iscsi_cid_count[ulp_num],
  1247. phba->fw_config.
  1248. iscsi_cid_start[ulp_num],
  1249. phba->fw_config.
  1250. iscsi_icd_count[ulp_num],
  1251. phba->fw_config.
  1252. iscsi_icd_start[ulp_num]);
  1253. }
  1254. }
  1255. if (phba->fw_config.ulp_supported == 0) {
  1256. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1257. "BG_%d : iSCSI initiator mode not set: ULP0 %x ULP1 %x\n",
  1258. pfw_cfg->ulp[BEISCSI_ULP0].ulp_mode,
  1259. pfw_cfg->ulp[BEISCSI_ULP1].ulp_mode);
  1260. goto fail_init;
  1261. }
  1262. /**
  1263. * ICD is shared among ULPs. Use icd_count of any one loaded ULP
  1264. **/
  1265. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  1266. if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
  1267. break;
  1268. icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
  1269. if (icd_count == 0 || icd_count > 65536) {
  1270. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1271. "BG_%d: invalid ICD count %d\n", icd_count);
  1272. goto fail_init;
  1273. }
  1274. cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
  1275. BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
  1276. if (cid_count == 0 || cid_count > 4096) {
  1277. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1278. "BG_%d: invalid CID count %d\n", cid_count);
  1279. goto fail_init;
  1280. }
  1281. /**
  1282. * Check FW is dual ULP aware i.e. can handle either
  1283. * of the protocols.
  1284. */
  1285. phba->fw_config.dual_ulp_aware = (pfw_cfg->function_mode &
  1286. BEISCSI_FUNC_DUA_MODE);
  1287. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1288. "BG_%d : DUA Mode : 0x%x\n",
  1289. phba->fw_config.dual_ulp_aware);
  1290. /* all set, continue using this FW config */
  1291. status = 0;
  1292. fail_init:
  1293. mutex_unlock(&ctrl->mbox_lock);
  1294. return status;
  1295. }
  1296. /**
  1297. * beiscsi_get_port_name()- Get port name for the function
  1298. * @ctrl: ptr to Ctrl Info
  1299. * @phba: ptr to the dev priv structure
  1300. *
  1301. * Get the alphanumeric character for port
  1302. *
  1303. **/
  1304. int beiscsi_get_port_name(struct be_ctrl_info *ctrl, struct beiscsi_hba *phba)
  1305. {
  1306. int ret = 0;
  1307. struct be_mcc_wrb *wrb;
  1308. struct be_cmd_get_port_name *ioctl;
  1309. mutex_lock(&ctrl->mbox_lock);
  1310. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1311. memset(wrb, 0, sizeof(*wrb));
  1312. ioctl = embedded_payload(wrb);
  1313. be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
  1314. be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
  1315. OPCODE_COMMON_GET_PORT_NAME,
  1316. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1317. ret = be_mbox_notify(ctrl);
  1318. phba->port_name = 0;
  1319. if (!ret) {
  1320. phba->port_name = ioctl->p.resp.port_names >>
  1321. (phba->fw_config.phys_port * 8) & 0xff;
  1322. } else {
  1323. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1324. "BG_%d : GET_PORT_NAME ret 0x%x status 0x%x\n",
  1325. ret, ioctl->h.resp_hdr.status);
  1326. }
  1327. if (phba->port_name == 0)
  1328. phba->port_name = '?';
  1329. mutex_unlock(&ctrl->mbox_lock);
  1330. return ret;
  1331. }
  1332. int beiscsi_set_host_data(struct beiscsi_hba *phba)
  1333. {
  1334. struct be_ctrl_info *ctrl = &phba->ctrl;
  1335. struct be_cmd_set_host_data *ioctl;
  1336. struct be_mcc_wrb *wrb;
  1337. int ret = 0;
  1338. if (is_chip_be2_be3r(phba))
  1339. return ret;
  1340. mutex_lock(&ctrl->mbox_lock);
  1341. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1342. memset(wrb, 0, sizeof(*wrb));
  1343. ioctl = embedded_payload(wrb);
  1344. be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
  1345. be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
  1346. OPCODE_COMMON_SET_HOST_DATA,
  1347. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1348. ioctl->param.req.param_id = BE_CMD_SET_HOST_PARAM_ID;
  1349. ioctl->param.req.param_len =
  1350. snprintf((char *)ioctl->param.req.param_data,
  1351. sizeof(ioctl->param.req.param_data),
  1352. "Linux iSCSI v%s", BUILD_STR);
  1353. ioctl->param.req.param_len = ALIGN(ioctl->param.req.param_len + 1, 4);
  1354. if (ioctl->param.req.param_len > BE_CMD_MAX_DRV_VERSION)
  1355. ioctl->param.req.param_len = BE_CMD_MAX_DRV_VERSION;
  1356. ret = be_mbox_notify(ctrl);
  1357. if (!ret) {
  1358. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1359. "BG_%d : HBA set host driver version\n");
  1360. } else {
  1361. /**
  1362. * Check "MCC_STATUS_INVALID_LENGTH" for SKH.
  1363. * Older FW versions return this error.
  1364. */
  1365. if (ret == MCC_STATUS_ILLEGAL_REQUEST ||
  1366. ret == MCC_STATUS_INVALID_LENGTH)
  1367. __beiscsi_log(phba, KERN_INFO,
  1368. "BG_%d : HBA failed to set host driver version\n");
  1369. }
  1370. mutex_unlock(&ctrl->mbox_lock);
  1371. return ret;
  1372. }
  1373. int beiscsi_set_uer_feature(struct beiscsi_hba *phba)
  1374. {
  1375. struct be_ctrl_info *ctrl = &phba->ctrl;
  1376. struct be_cmd_set_features *ioctl;
  1377. struct be_mcc_wrb *wrb;
  1378. int ret = 0;
  1379. mutex_lock(&ctrl->mbox_lock);
  1380. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1381. memset(wrb, 0, sizeof(*wrb));
  1382. ioctl = embedded_payload(wrb);
  1383. be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
  1384. be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
  1385. OPCODE_COMMON_SET_FEATURES,
  1386. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1387. ioctl->feature = BE_CMD_SET_FEATURE_UER;
  1388. ioctl->param_len = sizeof(ioctl->param.req);
  1389. ioctl->param.req.uer = BE_CMD_UER_SUPP_BIT;
  1390. ret = be_mbox_notify(ctrl);
  1391. if (!ret) {
  1392. phba->ue2rp = ioctl->param.resp.ue2rp;
  1393. set_bit(BEISCSI_HBA_UER_SUPP, &phba->state);
  1394. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1395. "BG_%d : HBA error recovery supported\n");
  1396. } else {
  1397. /**
  1398. * Check "MCC_STATUS_INVALID_LENGTH" for SKH.
  1399. * Older FW versions return this error.
  1400. */
  1401. if (ret == MCC_STATUS_ILLEGAL_REQUEST ||
  1402. ret == MCC_STATUS_INVALID_LENGTH)
  1403. __beiscsi_log(phba, KERN_INFO,
  1404. "BG_%d : HBA error recovery not supported\n");
  1405. }
  1406. mutex_unlock(&ctrl->mbox_lock);
  1407. return ret;
  1408. }
  1409. static u32 beiscsi_get_post_stage(struct beiscsi_hba *phba)
  1410. {
  1411. u32 sem;
  1412. if (is_chip_be2_be3r(phba))
  1413. sem = ioread32(phba->csr_va + SLIPORT_SEMAPHORE_OFFSET_BEx);
  1414. else
  1415. pci_read_config_dword(phba->pcidev,
  1416. SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
  1417. return sem;
  1418. }
  1419. int beiscsi_check_fw_rdy(struct beiscsi_hba *phba)
  1420. {
  1421. u32 loop, post, rdy = 0;
  1422. loop = 1000;
  1423. while (loop--) {
  1424. post = beiscsi_get_post_stage(phba);
  1425. if (post & POST_ERROR_BIT)
  1426. break;
  1427. if ((post & POST_STAGE_MASK) == POST_STAGE_ARMFW_RDY) {
  1428. rdy = 1;
  1429. break;
  1430. }
  1431. msleep(60);
  1432. }
  1433. if (!rdy) {
  1434. __beiscsi_log(phba, KERN_ERR,
  1435. "BC_%d : FW not ready 0x%x\n", post);
  1436. }
  1437. return rdy;
  1438. }
  1439. int beiscsi_cmd_function_reset(struct beiscsi_hba *phba)
  1440. {
  1441. struct be_ctrl_info *ctrl = &phba->ctrl;
  1442. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1443. struct be_post_sgl_pages_req *req;
  1444. int status;
  1445. mutex_lock(&ctrl->mbox_lock);
  1446. req = embedded_payload(wrb);
  1447. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1448. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1449. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1450. status = be_mbox_notify(ctrl);
  1451. mutex_unlock(&ctrl->mbox_lock);
  1452. return status;
  1453. }
  1454. int beiscsi_cmd_special_wrb(struct be_ctrl_info *ctrl, u32 load)
  1455. {
  1456. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1457. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1458. u8 *endian_check;
  1459. int status;
  1460. mutex_lock(&ctrl->mbox_lock);
  1461. memset(wrb, 0, sizeof(*wrb));
  1462. endian_check = (u8 *) wrb;
  1463. if (load) {
  1464. /* to start communicating */
  1465. *endian_check++ = 0xFF;
  1466. *endian_check++ = 0x12;
  1467. *endian_check++ = 0x34;
  1468. *endian_check++ = 0xFF;
  1469. *endian_check++ = 0xFF;
  1470. *endian_check++ = 0x56;
  1471. *endian_check++ = 0x78;
  1472. *endian_check++ = 0xFF;
  1473. } else {
  1474. /* to stop communicating */
  1475. *endian_check++ = 0xFF;
  1476. *endian_check++ = 0xAA;
  1477. *endian_check++ = 0xBB;
  1478. *endian_check++ = 0xFF;
  1479. *endian_check++ = 0xFF;
  1480. *endian_check++ = 0xCC;
  1481. *endian_check++ = 0xDD;
  1482. *endian_check = 0xFF;
  1483. }
  1484. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  1485. status = be_mbox_notify(ctrl);
  1486. if (status)
  1487. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1488. "BC_%d : special WRB message failed\n");
  1489. mutex_unlock(&ctrl->mbox_lock);
  1490. return status;
  1491. }
  1492. int beiscsi_init_sliport(struct beiscsi_hba *phba)
  1493. {
  1494. int status;
  1495. /* check POST stage before talking to FW */
  1496. status = beiscsi_check_fw_rdy(phba);
  1497. if (!status)
  1498. return -EIO;
  1499. /* clear all error states after checking FW rdy */
  1500. phba->state &= ~BEISCSI_HBA_IN_ERR;
  1501. /* check again UER support */
  1502. phba->state &= ~BEISCSI_HBA_UER_SUPP;
  1503. /*
  1504. * SLI COMMON_FUNCTION_RESET completion is indicated by BMBX RDY bit.
  1505. * It should clean up any stale info in FW for this fn.
  1506. */
  1507. status = beiscsi_cmd_function_reset(phba);
  1508. if (status) {
  1509. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1510. "BC_%d : SLI Function Reset failed\n");
  1511. return status;
  1512. }
  1513. /* indicate driver is loading */
  1514. return beiscsi_cmd_special_wrb(&phba->ctrl, 1);
  1515. }
  1516. /**
  1517. * beiscsi_cmd_iscsi_cleanup()- Inform FW to cleanup EP data structures.
  1518. * @phba: pointer to dev priv structure
  1519. * @ulp: ULP number.
  1520. *
  1521. * return
  1522. * Success: 0
  1523. * Failure: Non-Zero Value
  1524. **/
  1525. int beiscsi_cmd_iscsi_cleanup(struct beiscsi_hba *phba, unsigned short ulp)
  1526. {
  1527. struct be_ctrl_info *ctrl = &phba->ctrl;
  1528. struct iscsi_cleanup_req_v1 *req_v1;
  1529. struct iscsi_cleanup_req *req;
  1530. u16 hdr_ring_id, data_ring_id;
  1531. struct be_mcc_wrb *wrb;
  1532. int status;
  1533. mutex_lock(&ctrl->mbox_lock);
  1534. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1535. hdr_ring_id = HWI_GET_DEF_HDRQ_ID(phba, ulp);
  1536. data_ring_id = HWI_GET_DEF_BUFQ_ID(phba, ulp);
  1537. if (is_chip_be2_be3r(phba)) {
  1538. req = embedded_payload(wrb);
  1539. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1540. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1541. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  1542. req->chute = (1 << ulp);
  1543. /* BE2/BE3 FW creates 8-bit ring id */
  1544. req->hdr_ring_id = hdr_ring_id;
  1545. req->data_ring_id = data_ring_id;
  1546. } else {
  1547. req_v1 = embedded_payload(wrb);
  1548. be_wrb_hdr_prepare(wrb, sizeof(*req_v1), true, 0);
  1549. be_cmd_hdr_prepare(&req_v1->hdr, CMD_SUBSYSTEM_ISCSI,
  1550. OPCODE_COMMON_ISCSI_CLEANUP,
  1551. sizeof(*req_v1));
  1552. req_v1->hdr.version = 1;
  1553. req_v1->chute = (1 << ulp);
  1554. req_v1->hdr_ring_id = cpu_to_le16(hdr_ring_id);
  1555. req_v1->data_ring_id = cpu_to_le16(data_ring_id);
  1556. }
  1557. status = be_mbox_notify(ctrl);
  1558. if (status)
  1559. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  1560. "BG_%d : %s failed %d\n", __func__, ulp);
  1561. mutex_unlock(&ctrl->mbox_lock);
  1562. return status;
  1563. }
  1564. /*
  1565. * beiscsi_detect_ue()- Detect Unrecoverable Error on adapter
  1566. * @phba: Driver priv structure
  1567. *
  1568. * Read registers linked to UE and check for the UE status
  1569. **/
  1570. int beiscsi_detect_ue(struct beiscsi_hba *phba)
  1571. {
  1572. uint32_t ue_mask_hi = 0, ue_mask_lo = 0;
  1573. uint32_t ue_hi = 0, ue_lo = 0;
  1574. uint8_t i = 0;
  1575. int ret = 0;
  1576. pci_read_config_dword(phba->pcidev,
  1577. PCICFG_UE_STATUS_LOW, &ue_lo);
  1578. pci_read_config_dword(phba->pcidev,
  1579. PCICFG_UE_STATUS_MASK_LOW,
  1580. &ue_mask_lo);
  1581. pci_read_config_dword(phba->pcidev,
  1582. PCICFG_UE_STATUS_HIGH,
  1583. &ue_hi);
  1584. pci_read_config_dword(phba->pcidev,
  1585. PCICFG_UE_STATUS_MASK_HI,
  1586. &ue_mask_hi);
  1587. ue_lo = (ue_lo & ~ue_mask_lo);
  1588. ue_hi = (ue_hi & ~ue_mask_hi);
  1589. if (ue_lo || ue_hi) {
  1590. set_bit(BEISCSI_HBA_IN_UE, &phba->state);
  1591. __beiscsi_log(phba, KERN_ERR,
  1592. "BC_%d : HBA error detected\n");
  1593. ret = 1;
  1594. }
  1595. if (ue_lo) {
  1596. for (i = 0; ue_lo; ue_lo >>= 1, i++) {
  1597. if (ue_lo & 1)
  1598. __beiscsi_log(phba, KERN_ERR,
  1599. "BC_%d : UE_LOW %s bit set\n",
  1600. desc_ue_status_low[i]);
  1601. }
  1602. }
  1603. if (ue_hi) {
  1604. for (i = 0; ue_hi; ue_hi >>= 1, i++) {
  1605. if (ue_hi & 1)
  1606. __beiscsi_log(phba, KERN_ERR,
  1607. "BC_%d : UE_HIGH %s bit set\n",
  1608. desc_ue_status_hi[i]);
  1609. }
  1610. }
  1611. return ret;
  1612. }
  1613. /*
  1614. * beiscsi_detect_tpe()- Detect Transient Parity Error on adapter
  1615. * @phba: Driver priv structure
  1616. *
  1617. * Read SLIPORT SEMAPHORE register to check for UER
  1618. *
  1619. **/
  1620. int beiscsi_detect_tpe(struct beiscsi_hba *phba)
  1621. {
  1622. u32 post, status;
  1623. int ret = 0;
  1624. post = beiscsi_get_post_stage(phba);
  1625. status = post & POST_STAGE_MASK;
  1626. if ((status & POST_ERR_RECOVERY_CODE_MASK) ==
  1627. POST_STAGE_RECOVERABLE_ERR) {
  1628. set_bit(BEISCSI_HBA_IN_TPE, &phba->state);
  1629. __beiscsi_log(phba, KERN_INFO,
  1630. "BC_%d : HBA error recoverable: 0x%x\n", post);
  1631. ret = 1;
  1632. } else {
  1633. __beiscsi_log(phba, KERN_INFO,
  1634. "BC_%d : HBA in UE: 0x%x\n", post);
  1635. }
  1636. return ret;
  1637. }