zfcp_fsf.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  13. #define ZFCP_REQ_NO_QTCB 0x00000008
  14. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  15. {
  16. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  17. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  18. "fsrth_1", NULL);
  19. }
  20. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  21. unsigned long timeout)
  22. {
  23. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  24. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  25. fsf_req->timer.expires = jiffies + timeout;
  26. add_timer(&fsf_req->timer);
  27. }
  28. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  29. {
  30. BUG_ON(!fsf_req->erp_action);
  31. fsf_req->timer.function = zfcp_erp_timeout_handler;
  32. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  33. fsf_req->timer.expires = jiffies + 30 * HZ;
  34. add_timer(&fsf_req->timer);
  35. }
  36. /* association between FSF command and FSF QTCB type */
  37. static u32 fsf_qtcb_type[] = {
  38. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  39. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  48. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  49. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  51. };
  52. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  53. {
  54. u16 subtable = table >> 16;
  55. u16 rule = table & 0xffff;
  56. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  57. if (subtable && subtable < ARRAY_SIZE(act_type))
  58. dev_warn(&adapter->ccw_device->dev,
  59. "Access denied according to ACT rule type %s, "
  60. "rule %d\n", act_type[subtable], rule);
  61. }
  62. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  63. struct zfcp_port *port)
  64. {
  65. struct fsf_qtcb_header *header = &req->qtcb->header;
  66. dev_warn(&req->adapter->ccw_device->dev,
  67. "Access denied to port 0x%016Lx\n",
  68. (unsigned long long)port->wwpn);
  69. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  70. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  71. zfcp_erp_port_access_denied(port, "fspad_1", req);
  72. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  73. }
  74. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  75. struct zfcp_unit *unit)
  76. {
  77. struct fsf_qtcb_header *header = &req->qtcb->header;
  78. dev_warn(&req->adapter->ccw_device->dev,
  79. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  80. (unsigned long long)unit->fcp_lun,
  81. (unsigned long long)unit->port->wwpn);
  82. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  83. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  84. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  85. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  86. }
  87. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  88. {
  89. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  90. "operational because of an unsupported FC class\n");
  91. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  92. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  93. }
  94. /**
  95. * zfcp_fsf_req_free - free memory used by fsf request
  96. * @fsf_req: pointer to struct zfcp_fsf_req
  97. */
  98. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  99. {
  100. if (likely(req->pool)) {
  101. mempool_free(req, req->pool);
  102. return;
  103. }
  104. if (req->qtcb) {
  105. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  106. return;
  107. }
  108. }
  109. /**
  110. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  111. * @adapter: pointer to struct zfcp_adapter
  112. *
  113. * Never ever call this without shutting down the adapter first.
  114. * Otherwise the adapter would continue using and corrupting s390 storage.
  115. * Included BUG_ON() call to ensure this is done.
  116. * ERP is supposed to be the only user of this function.
  117. */
  118. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  119. {
  120. struct zfcp_fsf_req *req, *tmp;
  121. unsigned long flags;
  122. LIST_HEAD(remove_queue);
  123. unsigned int i;
  124. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  125. spin_lock_irqsave(&adapter->req_list_lock, flags);
  126. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  127. list_splice_init(&adapter->req_list[i], &remove_queue);
  128. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  129. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  130. list_del(&req->list);
  131. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  132. zfcp_fsf_req_complete(req);
  133. }
  134. }
  135. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  136. {
  137. struct fsf_status_read_buffer *sr_buf = req->data;
  138. struct zfcp_adapter *adapter = req->adapter;
  139. struct zfcp_port *port;
  140. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  141. unsigned long flags;
  142. read_lock_irqsave(&zfcp_data.config_lock, flags);
  143. list_for_each_entry(port, &adapter->port_list_head, list)
  144. if (port->d_id == d_id) {
  145. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  146. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  147. return;
  148. }
  149. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  150. }
  151. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  152. struct fsf_link_down_info *link_down)
  153. {
  154. struct zfcp_adapter *adapter = req->adapter;
  155. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  156. return;
  157. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  158. zfcp_scsi_schedule_rports_block(adapter);
  159. if (!link_down)
  160. goto out;
  161. switch (link_down->error_code) {
  162. case FSF_PSQ_LINK_NO_LIGHT:
  163. dev_warn(&req->adapter->ccw_device->dev,
  164. "There is no light signal from the local "
  165. "fibre channel cable\n");
  166. break;
  167. case FSF_PSQ_LINK_WRAP_PLUG:
  168. dev_warn(&req->adapter->ccw_device->dev,
  169. "There is a wrap plug instead of a fibre "
  170. "channel cable\n");
  171. break;
  172. case FSF_PSQ_LINK_NO_FCP:
  173. dev_warn(&req->adapter->ccw_device->dev,
  174. "The adjacent fibre channel node does not "
  175. "support FCP\n");
  176. break;
  177. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  178. dev_warn(&req->adapter->ccw_device->dev,
  179. "The FCP device is suspended because of a "
  180. "firmware update\n");
  181. break;
  182. case FSF_PSQ_LINK_INVALID_WWPN:
  183. dev_warn(&req->adapter->ccw_device->dev,
  184. "The FCP device detected a WWPN that is "
  185. "duplicate or not valid\n");
  186. break;
  187. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  188. dev_warn(&req->adapter->ccw_device->dev,
  189. "The fibre channel fabric does not support NPIV\n");
  190. break;
  191. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  192. dev_warn(&req->adapter->ccw_device->dev,
  193. "The FCP adapter cannot support more NPIV ports\n");
  194. break;
  195. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  196. dev_warn(&req->adapter->ccw_device->dev,
  197. "The adjacent switch cannot support "
  198. "more NPIV ports\n");
  199. break;
  200. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  201. dev_warn(&req->adapter->ccw_device->dev,
  202. "The FCP adapter could not log in to the "
  203. "fibre channel fabric\n");
  204. break;
  205. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  206. dev_warn(&req->adapter->ccw_device->dev,
  207. "The WWPN assignment file on the FCP adapter "
  208. "has been damaged\n");
  209. break;
  210. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  211. dev_warn(&req->adapter->ccw_device->dev,
  212. "The mode table on the FCP adapter "
  213. "has been damaged\n");
  214. break;
  215. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  216. dev_warn(&req->adapter->ccw_device->dev,
  217. "All NPIV ports on the FCP adapter have "
  218. "been assigned\n");
  219. break;
  220. default:
  221. dev_warn(&req->adapter->ccw_device->dev,
  222. "The link between the FCP adapter and "
  223. "the FC fabric is down\n");
  224. }
  225. out:
  226. zfcp_erp_adapter_failed(adapter, id, req);
  227. }
  228. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  229. {
  230. struct fsf_status_read_buffer *sr_buf = req->data;
  231. struct fsf_link_down_info *ldi =
  232. (struct fsf_link_down_info *) &sr_buf->payload;
  233. switch (sr_buf->status_subtype) {
  234. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  235. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  236. break;
  237. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  238. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  239. break;
  240. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  241. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  242. };
  243. }
  244. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  245. {
  246. struct zfcp_adapter *adapter = req->adapter;
  247. struct fsf_status_read_buffer *sr_buf = req->data;
  248. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  249. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  250. mempool_free(sr_buf, adapter->pool.data_status_read);
  251. zfcp_fsf_req_free(req);
  252. return;
  253. }
  254. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  255. switch (sr_buf->status_type) {
  256. case FSF_STATUS_READ_PORT_CLOSED:
  257. zfcp_fsf_status_read_port_closed(req);
  258. break;
  259. case FSF_STATUS_READ_INCOMING_ELS:
  260. zfcp_fc_incoming_els(req);
  261. break;
  262. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  263. break;
  264. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  265. dev_warn(&adapter->ccw_device->dev,
  266. "The error threshold for checksum statistics "
  267. "has been exceeded\n");
  268. zfcp_hba_dbf_event_berr(adapter, req);
  269. break;
  270. case FSF_STATUS_READ_LINK_DOWN:
  271. zfcp_fsf_status_read_link_down(req);
  272. break;
  273. case FSF_STATUS_READ_LINK_UP:
  274. dev_info(&adapter->ccw_device->dev,
  275. "The local link has been restored\n");
  276. /* All ports should be marked as ready to run again */
  277. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  278. ZFCP_STATUS_COMMON_RUNNING,
  279. ZFCP_SET);
  280. zfcp_erp_adapter_reopen(adapter,
  281. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  282. ZFCP_STATUS_COMMON_ERP_FAILED,
  283. "fssrh_2", req);
  284. break;
  285. case FSF_STATUS_READ_NOTIFICATION_LOST:
  286. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  287. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  288. req);
  289. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  290. schedule_work(&adapter->scan_work);
  291. break;
  292. case FSF_STATUS_READ_CFDC_UPDATED:
  293. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  294. break;
  295. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  296. adapter->adapter_features = sr_buf->payload.word[0];
  297. break;
  298. }
  299. mempool_free(sr_buf, adapter->pool.data_status_read);
  300. zfcp_fsf_req_free(req);
  301. atomic_inc(&adapter->stat_miss);
  302. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  303. }
  304. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  305. {
  306. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  307. case FSF_SQ_FCP_RSP_AVAILABLE:
  308. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  309. case FSF_SQ_NO_RETRY_POSSIBLE:
  310. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  311. return;
  312. case FSF_SQ_COMMAND_ABORTED:
  313. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  314. break;
  315. case FSF_SQ_NO_RECOM:
  316. dev_err(&req->adapter->ccw_device->dev,
  317. "The FCP adapter reported a problem "
  318. "that cannot be recovered\n");
  319. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  320. break;
  321. }
  322. /* all non-return stats set FSFREQ_ERROR*/
  323. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  324. }
  325. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  326. {
  327. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  328. return;
  329. switch (req->qtcb->header.fsf_status) {
  330. case FSF_UNKNOWN_COMMAND:
  331. dev_err(&req->adapter->ccw_device->dev,
  332. "The FCP adapter does not recognize the command 0x%x\n",
  333. req->qtcb->header.fsf_command);
  334. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  335. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  336. break;
  337. case FSF_ADAPTER_STATUS_AVAILABLE:
  338. zfcp_fsf_fsfstatus_qual_eval(req);
  339. break;
  340. }
  341. }
  342. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  343. {
  344. struct zfcp_adapter *adapter = req->adapter;
  345. struct fsf_qtcb *qtcb = req->qtcb;
  346. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  347. zfcp_hba_dbf_event_fsf_response(req);
  348. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  349. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  350. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  351. return;
  352. }
  353. switch (qtcb->prefix.prot_status) {
  354. case FSF_PROT_GOOD:
  355. case FSF_PROT_FSF_STATUS_PRESENTED:
  356. return;
  357. case FSF_PROT_QTCB_VERSION_ERROR:
  358. dev_err(&adapter->ccw_device->dev,
  359. "QTCB version 0x%x not supported by FCP adapter "
  360. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  361. psq->word[0], psq->word[1]);
  362. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  363. break;
  364. case FSF_PROT_ERROR_STATE:
  365. case FSF_PROT_SEQ_NUMB_ERROR:
  366. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  367. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  368. break;
  369. case FSF_PROT_UNSUPP_QTCB_TYPE:
  370. dev_err(&adapter->ccw_device->dev,
  371. "The QTCB type is not supported by the FCP adapter\n");
  372. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  373. break;
  374. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  375. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  376. &adapter->status);
  377. break;
  378. case FSF_PROT_DUPLICATE_REQUEST_ID:
  379. dev_err(&adapter->ccw_device->dev,
  380. "0x%Lx is an ambiguous request identifier\n",
  381. (unsigned long long)qtcb->bottom.support.req_handle);
  382. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  383. break;
  384. case FSF_PROT_LINK_DOWN:
  385. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  386. &psq->link_down_info);
  387. /* FIXME: reopening adapter now? better wait for link up */
  388. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  389. break;
  390. case FSF_PROT_REEST_QUEUE:
  391. /* All ports should be marked as ready to run again */
  392. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  393. ZFCP_STATUS_COMMON_RUNNING,
  394. ZFCP_SET);
  395. zfcp_erp_adapter_reopen(adapter,
  396. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  397. ZFCP_STATUS_COMMON_ERP_FAILED,
  398. "fspse_8", req);
  399. break;
  400. default:
  401. dev_err(&adapter->ccw_device->dev,
  402. "0x%x is not a valid transfer protocol status\n",
  403. qtcb->prefix.prot_status);
  404. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  405. }
  406. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  407. }
  408. /**
  409. * zfcp_fsf_req_complete - process completion of a FSF request
  410. * @fsf_req: The FSF request that has been completed.
  411. *
  412. * When a request has been completed either from the FCP adapter,
  413. * or it has been dismissed due to a queue shutdown, this function
  414. * is called to process the completion status and trigger further
  415. * events related to the FSF request.
  416. */
  417. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  418. {
  419. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  420. zfcp_fsf_status_read_handler(req);
  421. return;
  422. }
  423. del_timer(&req->timer);
  424. zfcp_fsf_protstatus_eval(req);
  425. zfcp_fsf_fsfstatus_eval(req);
  426. req->handler(req);
  427. if (req->erp_action)
  428. zfcp_erp_notify(req->erp_action, 0);
  429. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  430. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  431. zfcp_fsf_req_free(req);
  432. else
  433. /* notify initiator waiting for the requests completion */
  434. /*
  435. * FIXME: Race! We must not access fsf_req here as it might have been
  436. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  437. * flag. It's an improbable case. But, we have the same paranoia for
  438. * the cleanup flag already.
  439. * Might better be handled using complete()?
  440. * (setting the flag and doing wakeup ought to be atomic
  441. * with regard to checking the flag as long as waitqueue is
  442. * part of the to be released structure)
  443. */
  444. wake_up(&req->completion_wq);
  445. }
  446. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  447. {
  448. struct fsf_qtcb_bottom_config *bottom;
  449. struct zfcp_adapter *adapter = req->adapter;
  450. struct Scsi_Host *shost = adapter->scsi_host;
  451. bottom = &req->qtcb->bottom.config;
  452. if (req->data)
  453. memcpy(req->data, bottom, sizeof(*bottom));
  454. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  455. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  456. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  457. fc_host_speed(shost) = bottom->fc_link_speed;
  458. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  459. adapter->hydra_version = bottom->adapter_type;
  460. adapter->timer_ticks = bottom->timer_interval;
  461. if (fc_host_permanent_port_name(shost) == -1)
  462. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  463. switch (bottom->fc_topology) {
  464. case FSF_TOPO_P2P:
  465. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  466. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  467. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  468. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  469. break;
  470. case FSF_TOPO_FABRIC:
  471. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  472. break;
  473. case FSF_TOPO_AL:
  474. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  475. default:
  476. dev_err(&adapter->ccw_device->dev,
  477. "Unknown or unsupported arbitrated loop "
  478. "fibre channel topology detected\n");
  479. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  480. return -EIO;
  481. }
  482. return 0;
  483. }
  484. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  485. {
  486. struct zfcp_adapter *adapter = req->adapter;
  487. struct fsf_qtcb *qtcb = req->qtcb;
  488. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  489. struct Scsi_Host *shost = adapter->scsi_host;
  490. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  491. return;
  492. adapter->fsf_lic_version = bottom->lic_version;
  493. adapter->adapter_features = bottom->adapter_features;
  494. adapter->connection_features = bottom->connection_features;
  495. adapter->peer_wwpn = 0;
  496. adapter->peer_wwnn = 0;
  497. adapter->peer_d_id = 0;
  498. switch (qtcb->header.fsf_status) {
  499. case FSF_GOOD:
  500. if (zfcp_fsf_exchange_config_evaluate(req))
  501. return;
  502. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  503. dev_err(&adapter->ccw_device->dev,
  504. "FCP adapter maximum QTCB size (%d bytes) "
  505. "is too small\n",
  506. bottom->max_qtcb_size);
  507. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  508. return;
  509. }
  510. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  511. &adapter->status);
  512. break;
  513. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  514. fc_host_node_name(shost) = 0;
  515. fc_host_port_name(shost) = 0;
  516. fc_host_port_id(shost) = 0;
  517. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  518. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  519. adapter->hydra_version = 0;
  520. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  521. &adapter->status);
  522. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  523. &qtcb->header.fsf_status_qual.link_down_info);
  524. break;
  525. default:
  526. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  527. return;
  528. }
  529. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  530. adapter->hardware_version = bottom->hardware_version;
  531. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  532. min(FC_SERIAL_NUMBER_SIZE, 17));
  533. EBCASC(fc_host_serial_number(shost),
  534. min(FC_SERIAL_NUMBER_SIZE, 17));
  535. }
  536. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  537. dev_err(&adapter->ccw_device->dev,
  538. "The FCP adapter only supports newer "
  539. "control block versions\n");
  540. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  541. return;
  542. }
  543. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  544. dev_err(&adapter->ccw_device->dev,
  545. "The FCP adapter only supports older "
  546. "control block versions\n");
  547. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  548. }
  549. }
  550. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  551. {
  552. struct zfcp_adapter *adapter = req->adapter;
  553. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  554. struct Scsi_Host *shost = adapter->scsi_host;
  555. if (req->data)
  556. memcpy(req->data, bottom, sizeof(*bottom));
  557. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  558. fc_host_permanent_port_name(shost) = bottom->wwpn;
  559. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  560. } else
  561. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  562. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  563. fc_host_supported_speeds(shost) = bottom->supported_speed;
  564. }
  565. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  566. {
  567. struct fsf_qtcb *qtcb = req->qtcb;
  568. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  569. return;
  570. switch (qtcb->header.fsf_status) {
  571. case FSF_GOOD:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. break;
  574. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  575. zfcp_fsf_exchange_port_evaluate(req);
  576. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  577. &qtcb->header.fsf_status_qual.link_down_info);
  578. break;
  579. }
  580. }
  581. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  582. __releases(&adapter->req_q_lock)
  583. __acquires(&adapter->req_q_lock)
  584. {
  585. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  586. long ret;
  587. if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
  588. return -EIO;
  589. if (atomic_read(&req_q->count) > 0)
  590. return 0;
  591. atomic_dec(&req_q->count);
  592. spin_unlock_bh(&adapter->req_q_lock);
  593. ret = wait_event_interruptible_timeout(adapter->request_wq,
  594. atomic_read(&req_q->count) >= 0,
  595. 5 * HZ);
  596. spin_lock_bh(&adapter->req_q_lock);
  597. atomic_inc(&req_q->count);
  598. if (ret > 0)
  599. return 0;
  600. if (!ret)
  601. atomic_inc(&adapter->qdio_outb_full);
  602. return -EIO;
  603. }
  604. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  605. {
  606. struct zfcp_fsf_req *req;
  607. req = mempool_alloc(pool, GFP_ATOMIC);
  608. if (!req)
  609. return NULL;
  610. memset(req, 0, sizeof(*req));
  611. req->pool = pool;
  612. return req;
  613. }
  614. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  615. {
  616. struct zfcp_fsf_req_qtcb *qtcb;
  617. if (likely(pool))
  618. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  619. else
  620. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  621. GFP_ATOMIC);
  622. if (unlikely(!qtcb))
  623. return NULL;
  624. memset(qtcb, 0, sizeof(*qtcb));
  625. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  626. qtcb->fsf_req.pool = pool;
  627. return &qtcb->fsf_req;
  628. }
  629. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  630. u32 fsf_cmd, int req_flags,
  631. mempool_t *pool)
  632. {
  633. struct qdio_buffer_element *sbale;
  634. struct zfcp_fsf_req *req;
  635. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  636. if (req_flags & ZFCP_REQ_NO_QTCB)
  637. req = zfcp_fsf_alloc_noqtcb(pool);
  638. else
  639. req = zfcp_fsf_alloc_qtcb(pool);
  640. if (unlikely(!req))
  641. return ERR_PTR(-EIO);
  642. if (adapter->req_no == 0)
  643. adapter->req_no++;
  644. INIT_LIST_HEAD(&req->list);
  645. init_timer(&req->timer);
  646. init_waitqueue_head(&req->completion_wq);
  647. req->adapter = adapter;
  648. req->fsf_command = fsf_cmd;
  649. req->req_id = adapter->req_no;
  650. req->sbal_number = 1;
  651. req->sbal_first = req_q->first;
  652. req->sbal_last = req_q->first;
  653. req->sbale_curr = 1;
  654. sbale = zfcp_qdio_sbale_req(req);
  655. sbale[0].addr = (void *) req->req_id;
  656. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  657. if (likely(req->qtcb)) {
  658. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  659. req->qtcb->prefix.req_id = req->req_id;
  660. req->qtcb->prefix.ulp_info = 26;
  661. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  662. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  663. req->qtcb->header.req_handle = req->req_id;
  664. req->qtcb->header.fsf_command = req->fsf_command;
  665. req->seq_no = adapter->fsf_req_seq_no;
  666. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  667. sbale[1].addr = (void *) req->qtcb;
  668. sbale[1].length = sizeof(struct fsf_qtcb);
  669. }
  670. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  671. zfcp_fsf_req_free(req);
  672. return ERR_PTR(-EIO);
  673. }
  674. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  675. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  676. return req;
  677. }
  678. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  679. {
  680. struct zfcp_adapter *adapter = req->adapter;
  681. unsigned long flags;
  682. int idx;
  683. int with_qtcb = (req->qtcb != NULL);
  684. /* put allocated FSF request into hash table */
  685. spin_lock_irqsave(&adapter->req_list_lock, flags);
  686. idx = zfcp_reqlist_hash(req->req_id);
  687. list_add_tail(&req->list, &adapter->req_list[idx]);
  688. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  689. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  690. req->issued = get_clock();
  691. if (zfcp_qdio_send(req)) {
  692. del_timer(&req->timer);
  693. spin_lock_irqsave(&adapter->req_list_lock, flags);
  694. /* lookup request again, list might have changed */
  695. if (zfcp_reqlist_find_safe(adapter, req))
  696. zfcp_reqlist_remove(adapter, req);
  697. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  698. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  699. return -EIO;
  700. }
  701. /* Don't increase for unsolicited status */
  702. if (with_qtcb)
  703. adapter->fsf_req_seq_no++;
  704. adapter->req_no++;
  705. return 0;
  706. }
  707. /**
  708. * zfcp_fsf_status_read - send status read request
  709. * @adapter: pointer to struct zfcp_adapter
  710. * @req_flags: request flags
  711. * Returns: 0 on success, ERROR otherwise
  712. */
  713. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  714. {
  715. struct zfcp_fsf_req *req;
  716. struct fsf_status_read_buffer *sr_buf;
  717. struct qdio_buffer_element *sbale;
  718. int retval = -EIO;
  719. spin_lock_bh(&adapter->req_q_lock);
  720. if (zfcp_fsf_req_sbal_get(adapter))
  721. goto out;
  722. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  723. ZFCP_REQ_NO_QTCB,
  724. adapter->pool.fsf_req_status_read);
  725. if (IS_ERR(req)) {
  726. retval = PTR_ERR(req);
  727. goto out;
  728. }
  729. sbale = zfcp_qdio_sbale_req(req);
  730. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  731. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  732. req->sbale_curr = 2;
  733. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  734. if (!sr_buf) {
  735. retval = -ENOMEM;
  736. goto failed_buf;
  737. }
  738. memset(sr_buf, 0, sizeof(*sr_buf));
  739. req->data = sr_buf;
  740. sbale = zfcp_qdio_sbale_curr(req);
  741. sbale->addr = (void *) sr_buf;
  742. sbale->length = sizeof(*sr_buf);
  743. retval = zfcp_fsf_req_send(req);
  744. if (retval)
  745. goto failed_req_send;
  746. goto out;
  747. failed_req_send:
  748. mempool_free(sr_buf, adapter->pool.data_status_read);
  749. failed_buf:
  750. zfcp_fsf_req_free(req);
  751. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  752. out:
  753. spin_unlock_bh(&adapter->req_q_lock);
  754. return retval;
  755. }
  756. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  757. {
  758. struct zfcp_unit *unit = req->data;
  759. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  760. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  761. return;
  762. switch (req->qtcb->header.fsf_status) {
  763. case FSF_PORT_HANDLE_NOT_VALID:
  764. if (fsq->word[0] == fsq->word[1]) {
  765. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  766. "fsafch1", req);
  767. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  768. }
  769. break;
  770. case FSF_LUN_HANDLE_NOT_VALID:
  771. if (fsq->word[0] == fsq->word[1]) {
  772. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  773. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  774. }
  775. break;
  776. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  777. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  778. break;
  779. case FSF_PORT_BOXED:
  780. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  781. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  782. ZFCP_STATUS_FSFREQ_RETRY;
  783. break;
  784. case FSF_LUN_BOXED:
  785. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  786. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  787. ZFCP_STATUS_FSFREQ_RETRY;
  788. break;
  789. case FSF_ADAPTER_STATUS_AVAILABLE:
  790. switch (fsq->word[0]) {
  791. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  792. zfcp_test_link(unit->port);
  793. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  794. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  795. break;
  796. }
  797. break;
  798. case FSF_GOOD:
  799. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  800. break;
  801. }
  802. }
  803. /**
  804. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  805. * @old_req_id: unsigned long
  806. * @unit: pointer to struct zfcp_unit
  807. * Returns: pointer to struct zfcp_fsf_req
  808. */
  809. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  810. struct zfcp_unit *unit)
  811. {
  812. struct qdio_buffer_element *sbale;
  813. struct zfcp_fsf_req *req = NULL;
  814. struct zfcp_adapter *adapter = unit->port->adapter;
  815. spin_lock_bh(&adapter->req_q_lock);
  816. if (zfcp_fsf_req_sbal_get(adapter))
  817. goto out;
  818. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  819. 0, adapter->pool.fsf_req_abort);
  820. if (IS_ERR(req)) {
  821. req = NULL;
  822. goto out;
  823. }
  824. if (unlikely(!(atomic_read(&unit->status) &
  825. ZFCP_STATUS_COMMON_UNBLOCKED)))
  826. goto out_error_free;
  827. sbale = zfcp_qdio_sbale_req(req);
  828. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  829. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  830. req->data = unit;
  831. req->handler = zfcp_fsf_abort_fcp_command_handler;
  832. req->qtcb->header.lun_handle = unit->handle;
  833. req->qtcb->header.port_handle = unit->port->handle;
  834. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  835. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  836. if (!zfcp_fsf_req_send(req))
  837. goto out;
  838. out_error_free:
  839. zfcp_fsf_req_free(req);
  840. req = NULL;
  841. out:
  842. spin_unlock_bh(&adapter->req_q_lock);
  843. return req;
  844. }
  845. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  846. {
  847. struct zfcp_adapter *adapter = req->adapter;
  848. struct zfcp_send_ct *send_ct = req->data;
  849. struct fsf_qtcb_header *header = &req->qtcb->header;
  850. send_ct->status = -EINVAL;
  851. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  852. goto skip_fsfstatus;
  853. switch (header->fsf_status) {
  854. case FSF_GOOD:
  855. zfcp_san_dbf_event_ct_response(req);
  856. send_ct->status = 0;
  857. break;
  858. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  859. zfcp_fsf_class_not_supp(req);
  860. break;
  861. case FSF_ADAPTER_STATUS_AVAILABLE:
  862. switch (header->fsf_status_qual.word[0]){
  863. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  864. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  865. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  866. break;
  867. }
  868. break;
  869. case FSF_ACCESS_DENIED:
  870. break;
  871. case FSF_PORT_BOXED:
  872. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  873. ZFCP_STATUS_FSFREQ_RETRY;
  874. break;
  875. case FSF_PORT_HANDLE_NOT_VALID:
  876. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  877. case FSF_GENERIC_COMMAND_REJECTED:
  878. case FSF_PAYLOAD_SIZE_MISMATCH:
  879. case FSF_REQUEST_SIZE_TOO_LARGE:
  880. case FSF_RESPONSE_SIZE_TOO_LARGE:
  881. case FSF_SBAL_MISMATCH:
  882. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  883. break;
  884. }
  885. skip_fsfstatus:
  886. if (send_ct->handler)
  887. send_ct->handler(send_ct->handler_data);
  888. }
  889. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  890. struct scatterlist *sg_req,
  891. struct scatterlist *sg_resp,
  892. int max_sbals)
  893. {
  894. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  895. u32 feat = req->adapter->adapter_features;
  896. int bytes;
  897. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  898. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  899. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  900. return -EOPNOTSUPP;
  901. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  902. sbale[2].addr = sg_virt(sg_req);
  903. sbale[2].length = sg_req->length;
  904. sbale[3].addr = sg_virt(sg_resp);
  905. sbale[3].length = sg_resp->length;
  906. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  907. return 0;
  908. }
  909. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  910. sg_req, max_sbals);
  911. if (bytes <= 0)
  912. return -ENOMEM;
  913. req->qtcb->bottom.support.req_buf_length = bytes;
  914. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  915. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  916. sg_resp, max_sbals);
  917. if (bytes <= 0)
  918. return -ENOMEM;
  919. req->qtcb->bottom.support.resp_buf_length = bytes;
  920. return 0;
  921. }
  922. /**
  923. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  924. * @ct: pointer to struct zfcp_send_ct with data for request
  925. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  926. * @erp_action: if non-null the Generic Service request sent within ERP
  927. */
  928. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  929. struct zfcp_erp_action *erp_action)
  930. {
  931. struct zfcp_wka_port *wka_port = ct->wka_port;
  932. struct zfcp_adapter *adapter = wka_port->adapter;
  933. struct zfcp_fsf_req *req;
  934. int ret = -EIO;
  935. spin_lock_bh(&adapter->req_q_lock);
  936. if (zfcp_fsf_req_sbal_get(adapter))
  937. goto out;
  938. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  939. ZFCP_REQ_AUTO_CLEANUP, pool);
  940. if (IS_ERR(req)) {
  941. ret = PTR_ERR(req);
  942. goto out;
  943. }
  944. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  945. FSF_MAX_SBALS_PER_REQ);
  946. if (ret)
  947. goto failed_send;
  948. req->handler = zfcp_fsf_send_ct_handler;
  949. req->qtcb->header.port_handle = wka_port->handle;
  950. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  951. req->qtcb->bottom.support.timeout = ct->timeout;
  952. req->data = ct;
  953. zfcp_san_dbf_event_ct_request(req);
  954. if (erp_action) {
  955. erp_action->fsf_req = req;
  956. req->erp_action = erp_action;
  957. zfcp_fsf_start_erp_timer(req);
  958. } else
  959. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  960. ret = zfcp_fsf_req_send(req);
  961. if (ret)
  962. goto failed_send;
  963. goto out;
  964. failed_send:
  965. zfcp_fsf_req_free(req);
  966. if (erp_action)
  967. erp_action->fsf_req = NULL;
  968. out:
  969. spin_unlock_bh(&adapter->req_q_lock);
  970. return ret;
  971. }
  972. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  973. {
  974. struct zfcp_send_els *send_els = req->data;
  975. struct zfcp_port *port = send_els->port;
  976. struct fsf_qtcb_header *header = &req->qtcb->header;
  977. send_els->status = -EINVAL;
  978. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  979. goto skip_fsfstatus;
  980. switch (header->fsf_status) {
  981. case FSF_GOOD:
  982. zfcp_san_dbf_event_els_response(req);
  983. send_els->status = 0;
  984. break;
  985. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  986. zfcp_fsf_class_not_supp(req);
  987. break;
  988. case FSF_ADAPTER_STATUS_AVAILABLE:
  989. switch (header->fsf_status_qual.word[0]){
  990. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  991. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  992. zfcp_test_link(port);
  993. /*fall through */
  994. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  995. case FSF_SQ_RETRY_IF_POSSIBLE:
  996. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  997. break;
  998. }
  999. break;
  1000. case FSF_ELS_COMMAND_REJECTED:
  1001. case FSF_PAYLOAD_SIZE_MISMATCH:
  1002. case FSF_REQUEST_SIZE_TOO_LARGE:
  1003. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1004. break;
  1005. case FSF_ACCESS_DENIED:
  1006. zfcp_fsf_access_denied_port(req, port);
  1007. break;
  1008. case FSF_SBAL_MISMATCH:
  1009. /* should never occure, avoided in zfcp_fsf_send_els */
  1010. /* fall through */
  1011. default:
  1012. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1013. break;
  1014. }
  1015. skip_fsfstatus:
  1016. if (send_els->handler)
  1017. send_els->handler(send_els->handler_data);
  1018. }
  1019. /**
  1020. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1021. * @els: pointer to struct zfcp_send_els with data for the command
  1022. */
  1023. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1024. {
  1025. struct zfcp_fsf_req *req;
  1026. struct zfcp_adapter *adapter = els->adapter;
  1027. struct fsf_qtcb_bottom_support *bottom;
  1028. int ret = -EIO;
  1029. spin_lock_bh(&adapter->req_q_lock);
  1030. if (zfcp_fsf_req_sbal_get(adapter))
  1031. goto out;
  1032. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1033. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1034. if (IS_ERR(req)) {
  1035. ret = PTR_ERR(req);
  1036. goto out;
  1037. }
  1038. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1039. if (ret)
  1040. goto failed_send;
  1041. bottom = &req->qtcb->bottom.support;
  1042. req->handler = zfcp_fsf_send_els_handler;
  1043. bottom->d_id = els->d_id;
  1044. bottom->service_class = FSF_CLASS_3;
  1045. bottom->timeout = 2 * R_A_TOV;
  1046. req->data = els;
  1047. zfcp_san_dbf_event_els_request(req);
  1048. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1049. ret = zfcp_fsf_req_send(req);
  1050. if (ret)
  1051. goto failed_send;
  1052. goto out;
  1053. failed_send:
  1054. zfcp_fsf_req_free(req);
  1055. out:
  1056. spin_unlock_bh(&adapter->req_q_lock);
  1057. return ret;
  1058. }
  1059. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1060. {
  1061. struct qdio_buffer_element *sbale;
  1062. struct zfcp_fsf_req *req;
  1063. struct zfcp_adapter *adapter = erp_action->adapter;
  1064. int retval = -EIO;
  1065. spin_lock_bh(&adapter->req_q_lock);
  1066. if (zfcp_fsf_req_sbal_get(adapter))
  1067. goto out;
  1068. req = zfcp_fsf_req_create(adapter,
  1069. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1070. ZFCP_REQ_AUTO_CLEANUP,
  1071. adapter->pool.fsf_req_erp);
  1072. if (IS_ERR(req)) {
  1073. retval = PTR_ERR(req);
  1074. goto out;
  1075. }
  1076. sbale = zfcp_qdio_sbale_req(req);
  1077. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1078. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1079. req->qtcb->bottom.config.feature_selection =
  1080. FSF_FEATURE_CFDC |
  1081. FSF_FEATURE_LUN_SHARING |
  1082. FSF_FEATURE_NOTIFICATION_LOST |
  1083. FSF_FEATURE_UPDATE_ALERT;
  1084. req->erp_action = erp_action;
  1085. req->handler = zfcp_fsf_exchange_config_data_handler;
  1086. erp_action->fsf_req = req;
  1087. zfcp_fsf_start_erp_timer(req);
  1088. retval = zfcp_fsf_req_send(req);
  1089. if (retval) {
  1090. zfcp_fsf_req_free(req);
  1091. erp_action->fsf_req = NULL;
  1092. }
  1093. out:
  1094. spin_unlock_bh(&adapter->req_q_lock);
  1095. return retval;
  1096. }
  1097. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1098. struct fsf_qtcb_bottom_config *data)
  1099. {
  1100. struct qdio_buffer_element *sbale;
  1101. struct zfcp_fsf_req *req = NULL;
  1102. int retval = -EIO;
  1103. spin_lock_bh(&adapter->req_q_lock);
  1104. if (zfcp_fsf_req_sbal_get(adapter))
  1105. goto out_unlock;
  1106. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1107. 0, NULL);
  1108. if (IS_ERR(req)) {
  1109. retval = PTR_ERR(req);
  1110. goto out_unlock;
  1111. }
  1112. sbale = zfcp_qdio_sbale_req(req);
  1113. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1114. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1115. req->handler = zfcp_fsf_exchange_config_data_handler;
  1116. req->qtcb->bottom.config.feature_selection =
  1117. FSF_FEATURE_CFDC |
  1118. FSF_FEATURE_LUN_SHARING |
  1119. FSF_FEATURE_NOTIFICATION_LOST |
  1120. FSF_FEATURE_UPDATE_ALERT;
  1121. if (data)
  1122. req->data = data;
  1123. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1124. retval = zfcp_fsf_req_send(req);
  1125. spin_unlock_bh(&adapter->req_q_lock);
  1126. if (!retval)
  1127. wait_event(req->completion_wq,
  1128. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1129. zfcp_fsf_req_free(req);
  1130. return retval;
  1131. out_unlock:
  1132. spin_unlock_bh(&adapter->req_q_lock);
  1133. return retval;
  1134. }
  1135. /**
  1136. * zfcp_fsf_exchange_port_data - request information about local port
  1137. * @erp_action: ERP action for the adapter for which port data is requested
  1138. * Returns: 0 on success, error otherwise
  1139. */
  1140. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1141. {
  1142. struct qdio_buffer_element *sbale;
  1143. struct zfcp_fsf_req *req;
  1144. struct zfcp_adapter *adapter = erp_action->adapter;
  1145. int retval = -EIO;
  1146. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1147. return -EOPNOTSUPP;
  1148. spin_lock_bh(&adapter->req_q_lock);
  1149. if (zfcp_fsf_req_sbal_get(adapter))
  1150. goto out;
  1151. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1152. ZFCP_REQ_AUTO_CLEANUP,
  1153. adapter->pool.fsf_req_erp);
  1154. if (IS_ERR(req)) {
  1155. retval = PTR_ERR(req);
  1156. goto out;
  1157. }
  1158. sbale = zfcp_qdio_sbale_req(req);
  1159. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1160. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1161. req->handler = zfcp_fsf_exchange_port_data_handler;
  1162. req->erp_action = erp_action;
  1163. erp_action->fsf_req = req;
  1164. zfcp_fsf_start_erp_timer(req);
  1165. retval = zfcp_fsf_req_send(req);
  1166. if (retval) {
  1167. zfcp_fsf_req_free(req);
  1168. erp_action->fsf_req = NULL;
  1169. }
  1170. out:
  1171. spin_unlock_bh(&adapter->req_q_lock);
  1172. return retval;
  1173. }
  1174. /**
  1175. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1176. * @adapter: pointer to struct zfcp_adapter
  1177. * @data: pointer to struct fsf_qtcb_bottom_port
  1178. * Returns: 0 on success, error otherwise
  1179. */
  1180. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1181. struct fsf_qtcb_bottom_port *data)
  1182. {
  1183. struct qdio_buffer_element *sbale;
  1184. struct zfcp_fsf_req *req = NULL;
  1185. int retval = -EIO;
  1186. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1187. return -EOPNOTSUPP;
  1188. spin_lock_bh(&adapter->req_q_lock);
  1189. if (zfcp_fsf_req_sbal_get(adapter))
  1190. goto out_unlock;
  1191. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1192. NULL);
  1193. if (IS_ERR(req)) {
  1194. retval = PTR_ERR(req);
  1195. goto out_unlock;
  1196. }
  1197. if (data)
  1198. req->data = data;
  1199. sbale = zfcp_qdio_sbale_req(req);
  1200. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1201. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1202. req->handler = zfcp_fsf_exchange_port_data_handler;
  1203. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1204. retval = zfcp_fsf_req_send(req);
  1205. spin_unlock_bh(&adapter->req_q_lock);
  1206. if (!retval)
  1207. wait_event(req->completion_wq,
  1208. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1209. zfcp_fsf_req_free(req);
  1210. return retval;
  1211. out_unlock:
  1212. spin_unlock_bh(&adapter->req_q_lock);
  1213. return retval;
  1214. }
  1215. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1216. {
  1217. struct zfcp_port *port = req->data;
  1218. struct fsf_qtcb_header *header = &req->qtcb->header;
  1219. struct fsf_plogi *plogi;
  1220. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1221. return;
  1222. switch (header->fsf_status) {
  1223. case FSF_PORT_ALREADY_OPEN:
  1224. break;
  1225. case FSF_ACCESS_DENIED:
  1226. zfcp_fsf_access_denied_port(req, port);
  1227. break;
  1228. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1229. dev_warn(&req->adapter->ccw_device->dev,
  1230. "Not enough FCP adapter resources to open "
  1231. "remote port 0x%016Lx\n",
  1232. (unsigned long long)port->wwpn);
  1233. zfcp_erp_port_failed(port, "fsoph_1", req);
  1234. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1235. break;
  1236. case FSF_ADAPTER_STATUS_AVAILABLE:
  1237. switch (header->fsf_status_qual.word[0]) {
  1238. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1239. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1240. case FSF_SQ_NO_RETRY_POSSIBLE:
  1241. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1242. break;
  1243. }
  1244. break;
  1245. case FSF_GOOD:
  1246. port->handle = header->port_handle;
  1247. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1248. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1249. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1250. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1251. &port->status);
  1252. /* check whether D_ID has changed during open */
  1253. /*
  1254. * FIXME: This check is not airtight, as the FCP channel does
  1255. * not monitor closures of target port connections caused on
  1256. * the remote side. Thus, they might miss out on invalidating
  1257. * locally cached WWPNs (and other N_Port parameters) of gone
  1258. * target ports. So, our heroic attempt to make things safe
  1259. * could be undermined by 'open port' response data tagged with
  1260. * obsolete WWPNs. Another reason to monitor potential
  1261. * connection closures ourself at least (by interpreting
  1262. * incoming ELS' and unsolicited status). It just crosses my
  1263. * mind that one should be able to cross-check by means of
  1264. * another GID_PN straight after a port has been opened.
  1265. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1266. */
  1267. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1268. if (req->qtcb->bottom.support.els1_length >=
  1269. FSF_PLOGI_MIN_LEN) {
  1270. if (plogi->serv_param.wwpn != port->wwpn)
  1271. port->d_id = 0;
  1272. else {
  1273. port->wwnn = plogi->serv_param.wwnn;
  1274. zfcp_fc_plogi_evaluate(port, plogi);
  1275. }
  1276. }
  1277. break;
  1278. case FSF_UNKNOWN_OP_SUBTYPE:
  1279. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1280. break;
  1281. }
  1282. }
  1283. /**
  1284. * zfcp_fsf_open_port - create and send open port request
  1285. * @erp_action: pointer to struct zfcp_erp_action
  1286. * Returns: 0 on success, error otherwise
  1287. */
  1288. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1289. {
  1290. struct qdio_buffer_element *sbale;
  1291. struct zfcp_adapter *adapter = erp_action->adapter;
  1292. struct zfcp_fsf_req *req;
  1293. int retval = -EIO;
  1294. spin_lock_bh(&adapter->req_q_lock);
  1295. if (zfcp_fsf_req_sbal_get(adapter))
  1296. goto out;
  1297. req = zfcp_fsf_req_create(adapter,
  1298. FSF_QTCB_OPEN_PORT_WITH_DID,
  1299. ZFCP_REQ_AUTO_CLEANUP,
  1300. adapter->pool.fsf_req_erp);
  1301. if (IS_ERR(req)) {
  1302. retval = PTR_ERR(req);
  1303. goto out;
  1304. }
  1305. sbale = zfcp_qdio_sbale_req(req);
  1306. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1307. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1308. req->handler = zfcp_fsf_open_port_handler;
  1309. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1310. req->data = erp_action->port;
  1311. req->erp_action = erp_action;
  1312. erp_action->fsf_req = req;
  1313. zfcp_fsf_start_erp_timer(req);
  1314. retval = zfcp_fsf_req_send(req);
  1315. if (retval) {
  1316. zfcp_fsf_req_free(req);
  1317. erp_action->fsf_req = NULL;
  1318. }
  1319. out:
  1320. spin_unlock_bh(&adapter->req_q_lock);
  1321. return retval;
  1322. }
  1323. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1324. {
  1325. struct zfcp_port *port = req->data;
  1326. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1327. return;
  1328. switch (req->qtcb->header.fsf_status) {
  1329. case FSF_PORT_HANDLE_NOT_VALID:
  1330. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1331. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1332. break;
  1333. case FSF_ADAPTER_STATUS_AVAILABLE:
  1334. break;
  1335. case FSF_GOOD:
  1336. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1337. ZFCP_STATUS_COMMON_OPEN,
  1338. ZFCP_CLEAR);
  1339. break;
  1340. }
  1341. }
  1342. /**
  1343. * zfcp_fsf_close_port - create and send close port request
  1344. * @erp_action: pointer to struct zfcp_erp_action
  1345. * Returns: 0 on success, error otherwise
  1346. */
  1347. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1348. {
  1349. struct qdio_buffer_element *sbale;
  1350. struct zfcp_adapter *adapter = erp_action->adapter;
  1351. struct zfcp_fsf_req *req;
  1352. int retval = -EIO;
  1353. spin_lock_bh(&adapter->req_q_lock);
  1354. if (zfcp_fsf_req_sbal_get(adapter))
  1355. goto out;
  1356. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1357. ZFCP_REQ_AUTO_CLEANUP,
  1358. adapter->pool.fsf_req_erp);
  1359. if (IS_ERR(req)) {
  1360. retval = PTR_ERR(req);
  1361. goto out;
  1362. }
  1363. sbale = zfcp_qdio_sbale_req(req);
  1364. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1365. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1366. req->handler = zfcp_fsf_close_port_handler;
  1367. req->data = erp_action->port;
  1368. req->erp_action = erp_action;
  1369. req->qtcb->header.port_handle = erp_action->port->handle;
  1370. erp_action->fsf_req = req;
  1371. zfcp_fsf_start_erp_timer(req);
  1372. retval = zfcp_fsf_req_send(req);
  1373. if (retval) {
  1374. zfcp_fsf_req_free(req);
  1375. erp_action->fsf_req = NULL;
  1376. }
  1377. out:
  1378. spin_unlock_bh(&adapter->req_q_lock);
  1379. return retval;
  1380. }
  1381. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1382. {
  1383. struct zfcp_wka_port *wka_port = req->data;
  1384. struct fsf_qtcb_header *header = &req->qtcb->header;
  1385. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1386. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1387. goto out;
  1388. }
  1389. switch (header->fsf_status) {
  1390. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1391. dev_warn(&req->adapter->ccw_device->dev,
  1392. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1393. case FSF_ADAPTER_STATUS_AVAILABLE:
  1394. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1395. case FSF_ACCESS_DENIED:
  1396. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1397. break;
  1398. case FSF_PORT_ALREADY_OPEN:
  1399. break;
  1400. case FSF_GOOD:
  1401. wka_port->handle = header->port_handle;
  1402. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1403. }
  1404. out:
  1405. wake_up(&wka_port->completion_wq);
  1406. }
  1407. /**
  1408. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1409. * @wka_port: pointer to struct zfcp_wka_port
  1410. * Returns: 0 on success, error otherwise
  1411. */
  1412. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1413. {
  1414. struct qdio_buffer_element *sbale;
  1415. struct zfcp_adapter *adapter = wka_port->adapter;
  1416. struct zfcp_fsf_req *req;
  1417. int retval = -EIO;
  1418. spin_lock_bh(&adapter->req_q_lock);
  1419. if (zfcp_fsf_req_sbal_get(adapter))
  1420. goto out;
  1421. req = zfcp_fsf_req_create(adapter,
  1422. FSF_QTCB_OPEN_PORT_WITH_DID,
  1423. ZFCP_REQ_AUTO_CLEANUP,
  1424. adapter->pool.fsf_req_erp);
  1425. if (unlikely(IS_ERR(req))) {
  1426. retval = PTR_ERR(req);
  1427. goto out;
  1428. }
  1429. sbale = zfcp_qdio_sbale_req(req);
  1430. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1431. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1432. req->handler = zfcp_fsf_open_wka_port_handler;
  1433. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1434. req->data = wka_port;
  1435. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1436. retval = zfcp_fsf_req_send(req);
  1437. if (retval)
  1438. zfcp_fsf_req_free(req);
  1439. out:
  1440. spin_unlock_bh(&adapter->req_q_lock);
  1441. return retval;
  1442. }
  1443. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1444. {
  1445. struct zfcp_wka_port *wka_port = req->data;
  1446. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1447. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1448. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1449. }
  1450. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1451. wake_up(&wka_port->completion_wq);
  1452. }
  1453. /**
  1454. * zfcp_fsf_close_wka_port - create and send close wka port request
  1455. * @erp_action: pointer to struct zfcp_erp_action
  1456. * Returns: 0 on success, error otherwise
  1457. */
  1458. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1459. {
  1460. struct qdio_buffer_element *sbale;
  1461. struct zfcp_adapter *adapter = wka_port->adapter;
  1462. struct zfcp_fsf_req *req;
  1463. int retval = -EIO;
  1464. spin_lock_bh(&adapter->req_q_lock);
  1465. if (zfcp_fsf_req_sbal_get(adapter))
  1466. goto out;
  1467. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1468. ZFCP_REQ_AUTO_CLEANUP,
  1469. adapter->pool.fsf_req_erp);
  1470. if (unlikely(IS_ERR(req))) {
  1471. retval = PTR_ERR(req);
  1472. goto out;
  1473. }
  1474. sbale = zfcp_qdio_sbale_req(req);
  1475. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1476. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1477. req->handler = zfcp_fsf_close_wka_port_handler;
  1478. req->data = wka_port;
  1479. req->qtcb->header.port_handle = wka_port->handle;
  1480. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1481. retval = zfcp_fsf_req_send(req);
  1482. if (retval)
  1483. zfcp_fsf_req_free(req);
  1484. out:
  1485. spin_unlock_bh(&adapter->req_q_lock);
  1486. return retval;
  1487. }
  1488. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1489. {
  1490. struct zfcp_port *port = req->data;
  1491. struct fsf_qtcb_header *header = &req->qtcb->header;
  1492. struct zfcp_unit *unit;
  1493. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1494. return;
  1495. switch (header->fsf_status) {
  1496. case FSF_PORT_HANDLE_NOT_VALID:
  1497. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1498. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1499. break;
  1500. case FSF_ACCESS_DENIED:
  1501. zfcp_fsf_access_denied_port(req, port);
  1502. break;
  1503. case FSF_PORT_BOXED:
  1504. zfcp_erp_port_boxed(port, "fscpph2", req);
  1505. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1506. ZFCP_STATUS_FSFREQ_RETRY;
  1507. /* can't use generic zfcp_erp_modify_port_status because
  1508. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1509. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1510. list_for_each_entry(unit, &port->unit_list_head, list)
  1511. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1512. &unit->status);
  1513. break;
  1514. case FSF_ADAPTER_STATUS_AVAILABLE:
  1515. switch (header->fsf_status_qual.word[0]) {
  1516. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1517. /* fall through */
  1518. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1519. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1520. break;
  1521. }
  1522. break;
  1523. case FSF_GOOD:
  1524. /* can't use generic zfcp_erp_modify_port_status because
  1525. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1526. */
  1527. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1528. list_for_each_entry(unit, &port->unit_list_head, list)
  1529. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1530. &unit->status);
  1531. break;
  1532. }
  1533. }
  1534. /**
  1535. * zfcp_fsf_close_physical_port - close physical port
  1536. * @erp_action: pointer to struct zfcp_erp_action
  1537. * Returns: 0 on success
  1538. */
  1539. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1540. {
  1541. struct qdio_buffer_element *sbale;
  1542. struct zfcp_adapter *adapter = erp_action->adapter;
  1543. struct zfcp_fsf_req *req;
  1544. int retval = -EIO;
  1545. spin_lock_bh(&adapter->req_q_lock);
  1546. if (zfcp_fsf_req_sbal_get(adapter))
  1547. goto out;
  1548. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1549. ZFCP_REQ_AUTO_CLEANUP,
  1550. adapter->pool.fsf_req_erp);
  1551. if (IS_ERR(req)) {
  1552. retval = PTR_ERR(req);
  1553. goto out;
  1554. }
  1555. sbale = zfcp_qdio_sbale_req(req);
  1556. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1557. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1558. req->data = erp_action->port;
  1559. req->qtcb->header.port_handle = erp_action->port->handle;
  1560. req->erp_action = erp_action;
  1561. req->handler = zfcp_fsf_close_physical_port_handler;
  1562. erp_action->fsf_req = req;
  1563. zfcp_fsf_start_erp_timer(req);
  1564. retval = zfcp_fsf_req_send(req);
  1565. if (retval) {
  1566. zfcp_fsf_req_free(req);
  1567. erp_action->fsf_req = NULL;
  1568. }
  1569. out:
  1570. spin_unlock_bh(&adapter->req_q_lock);
  1571. return retval;
  1572. }
  1573. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1574. {
  1575. struct zfcp_adapter *adapter = req->adapter;
  1576. struct zfcp_unit *unit = req->data;
  1577. struct fsf_qtcb_header *header = &req->qtcb->header;
  1578. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1579. struct fsf_queue_designator *queue_designator =
  1580. &header->fsf_status_qual.fsf_queue_designator;
  1581. int exclusive, readwrite;
  1582. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1583. return;
  1584. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1585. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1586. ZFCP_STATUS_UNIT_SHARED |
  1587. ZFCP_STATUS_UNIT_READONLY,
  1588. &unit->status);
  1589. switch (header->fsf_status) {
  1590. case FSF_PORT_HANDLE_NOT_VALID:
  1591. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1592. /* fall through */
  1593. case FSF_LUN_ALREADY_OPEN:
  1594. break;
  1595. case FSF_ACCESS_DENIED:
  1596. zfcp_fsf_access_denied_unit(req, unit);
  1597. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1598. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1599. break;
  1600. case FSF_PORT_BOXED:
  1601. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1602. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1603. ZFCP_STATUS_FSFREQ_RETRY;
  1604. break;
  1605. case FSF_LUN_SHARING_VIOLATION:
  1606. if (header->fsf_status_qual.word[0])
  1607. dev_warn(&adapter->ccw_device->dev,
  1608. "LUN 0x%Lx on port 0x%Lx is already in "
  1609. "use by CSS%d, MIF Image ID %x\n",
  1610. (unsigned long long)unit->fcp_lun,
  1611. (unsigned long long)unit->port->wwpn,
  1612. queue_designator->cssid,
  1613. queue_designator->hla);
  1614. else
  1615. zfcp_act_eval_err(adapter,
  1616. header->fsf_status_qual.word[2]);
  1617. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1618. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1619. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1620. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1621. break;
  1622. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1623. dev_warn(&adapter->ccw_device->dev,
  1624. "No handle is available for LUN "
  1625. "0x%016Lx on port 0x%016Lx\n",
  1626. (unsigned long long)unit->fcp_lun,
  1627. (unsigned long long)unit->port->wwpn);
  1628. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1629. /* fall through */
  1630. case FSF_INVALID_COMMAND_OPTION:
  1631. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1632. break;
  1633. case FSF_ADAPTER_STATUS_AVAILABLE:
  1634. switch (header->fsf_status_qual.word[0]) {
  1635. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1636. zfcp_test_link(unit->port);
  1637. /* fall through */
  1638. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1639. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1640. break;
  1641. }
  1642. break;
  1643. case FSF_GOOD:
  1644. unit->handle = header->lun_handle;
  1645. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1646. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1647. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1648. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1649. exclusive = (bottom->lun_access_info &
  1650. FSF_UNIT_ACCESS_EXCLUSIVE);
  1651. readwrite = (bottom->lun_access_info &
  1652. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1653. if (!exclusive)
  1654. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1655. &unit->status);
  1656. if (!readwrite) {
  1657. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1658. &unit->status);
  1659. dev_info(&adapter->ccw_device->dev,
  1660. "SCSI device at LUN 0x%016Lx on port "
  1661. "0x%016Lx opened read-only\n",
  1662. (unsigned long long)unit->fcp_lun,
  1663. (unsigned long long)unit->port->wwpn);
  1664. }
  1665. if (exclusive && !readwrite) {
  1666. dev_err(&adapter->ccw_device->dev,
  1667. "Exclusive read-only access not "
  1668. "supported (unit 0x%016Lx, "
  1669. "port 0x%016Lx)\n",
  1670. (unsigned long long)unit->fcp_lun,
  1671. (unsigned long long)unit->port->wwpn);
  1672. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1673. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1674. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1675. } else if (!exclusive && readwrite) {
  1676. dev_err(&adapter->ccw_device->dev,
  1677. "Shared read-write access not "
  1678. "supported (unit 0x%016Lx, port "
  1679. "0x%016Lx)\n",
  1680. (unsigned long long)unit->fcp_lun,
  1681. (unsigned long long)unit->port->wwpn);
  1682. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1684. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1685. }
  1686. }
  1687. break;
  1688. }
  1689. }
  1690. /**
  1691. * zfcp_fsf_open_unit - open unit
  1692. * @erp_action: pointer to struct zfcp_erp_action
  1693. * Returns: 0 on success, error otherwise
  1694. */
  1695. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1696. {
  1697. struct qdio_buffer_element *sbale;
  1698. struct zfcp_adapter *adapter = erp_action->adapter;
  1699. struct zfcp_fsf_req *req;
  1700. int retval = -EIO;
  1701. spin_lock_bh(&adapter->req_q_lock);
  1702. if (zfcp_fsf_req_sbal_get(adapter))
  1703. goto out;
  1704. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1705. ZFCP_REQ_AUTO_CLEANUP,
  1706. adapter->pool.fsf_req_erp);
  1707. if (IS_ERR(req)) {
  1708. retval = PTR_ERR(req);
  1709. goto out;
  1710. }
  1711. sbale = zfcp_qdio_sbale_req(req);
  1712. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1713. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1714. req->qtcb->header.port_handle = erp_action->port->handle;
  1715. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1716. req->handler = zfcp_fsf_open_unit_handler;
  1717. req->data = erp_action->unit;
  1718. req->erp_action = erp_action;
  1719. erp_action->fsf_req = req;
  1720. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1721. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1722. zfcp_fsf_start_erp_timer(req);
  1723. retval = zfcp_fsf_req_send(req);
  1724. if (retval) {
  1725. zfcp_fsf_req_free(req);
  1726. erp_action->fsf_req = NULL;
  1727. }
  1728. out:
  1729. spin_unlock_bh(&adapter->req_q_lock);
  1730. return retval;
  1731. }
  1732. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1733. {
  1734. struct zfcp_unit *unit = req->data;
  1735. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1736. return;
  1737. switch (req->qtcb->header.fsf_status) {
  1738. case FSF_PORT_HANDLE_NOT_VALID:
  1739. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1740. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1741. break;
  1742. case FSF_LUN_HANDLE_NOT_VALID:
  1743. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1744. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1745. break;
  1746. case FSF_PORT_BOXED:
  1747. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1748. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1749. ZFCP_STATUS_FSFREQ_RETRY;
  1750. break;
  1751. case FSF_ADAPTER_STATUS_AVAILABLE:
  1752. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1753. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1754. zfcp_test_link(unit->port);
  1755. /* fall through */
  1756. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1757. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1758. break;
  1759. }
  1760. break;
  1761. case FSF_GOOD:
  1762. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1763. break;
  1764. }
  1765. }
  1766. /**
  1767. * zfcp_fsf_close_unit - close zfcp unit
  1768. * @erp_action: pointer to struct zfcp_unit
  1769. * Returns: 0 on success, error otherwise
  1770. */
  1771. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1772. {
  1773. struct qdio_buffer_element *sbale;
  1774. struct zfcp_adapter *adapter = erp_action->adapter;
  1775. struct zfcp_fsf_req *req;
  1776. int retval = -EIO;
  1777. spin_lock_bh(&adapter->req_q_lock);
  1778. if (zfcp_fsf_req_sbal_get(adapter))
  1779. goto out;
  1780. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1781. ZFCP_REQ_AUTO_CLEANUP,
  1782. adapter->pool.fsf_req_erp);
  1783. if (IS_ERR(req)) {
  1784. retval = PTR_ERR(req);
  1785. goto out;
  1786. }
  1787. sbale = zfcp_qdio_sbale_req(req);
  1788. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1789. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1790. req->qtcb->header.port_handle = erp_action->port->handle;
  1791. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1792. req->handler = zfcp_fsf_close_unit_handler;
  1793. req->data = erp_action->unit;
  1794. req->erp_action = erp_action;
  1795. erp_action->fsf_req = req;
  1796. zfcp_fsf_start_erp_timer(req);
  1797. retval = zfcp_fsf_req_send(req);
  1798. if (retval) {
  1799. zfcp_fsf_req_free(req);
  1800. erp_action->fsf_req = NULL;
  1801. }
  1802. out:
  1803. spin_unlock_bh(&adapter->req_q_lock);
  1804. return retval;
  1805. }
  1806. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1807. {
  1808. lat_rec->sum += lat;
  1809. lat_rec->min = min(lat_rec->min, lat);
  1810. lat_rec->max = max(lat_rec->max, lat);
  1811. }
  1812. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1813. {
  1814. struct fsf_qual_latency_info *lat_inf;
  1815. struct latency_cont *lat;
  1816. struct zfcp_unit *unit = req->unit;
  1817. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1818. switch (req->qtcb->bottom.io.data_direction) {
  1819. case FSF_DATADIR_READ:
  1820. lat = &unit->latencies.read;
  1821. break;
  1822. case FSF_DATADIR_WRITE:
  1823. lat = &unit->latencies.write;
  1824. break;
  1825. case FSF_DATADIR_CMND:
  1826. lat = &unit->latencies.cmd;
  1827. break;
  1828. default:
  1829. return;
  1830. }
  1831. spin_lock(&unit->latencies.lock);
  1832. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1833. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1834. lat->counter++;
  1835. spin_unlock(&unit->latencies.lock);
  1836. }
  1837. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1838. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1839. {
  1840. struct fsf_qual_latency_info *lat_inf;
  1841. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1842. struct request *req = scsi_cmnd->request;
  1843. struct zfcp_blk_drv_data trace;
  1844. int ticks = fsf_req->adapter->timer_ticks;
  1845. trace.flags = 0;
  1846. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1847. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1848. trace.flags |= ZFCP_BLK_LAT_VALID;
  1849. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1850. trace.channel_lat = lat_inf->channel_lat * ticks;
  1851. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1852. }
  1853. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1854. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1855. trace.inb_usage = fsf_req->qdio_inb_usage;
  1856. trace.outb_usage = fsf_req->qdio_outb_usage;
  1857. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1858. }
  1859. #else
  1860. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1861. {
  1862. }
  1863. #endif
  1864. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1865. {
  1866. struct scsi_cmnd *scpnt;
  1867. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1868. &(req->qtcb->bottom.io.fcp_rsp);
  1869. u32 sns_len;
  1870. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1871. unsigned long flags;
  1872. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1873. scpnt = req->data;
  1874. if (unlikely(!scpnt)) {
  1875. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1876. return;
  1877. }
  1878. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1879. set_host_byte(scpnt, DID_SOFT_ERROR);
  1880. goto skip_fsfstatus;
  1881. }
  1882. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1883. set_host_byte(scpnt, DID_ERROR);
  1884. goto skip_fsfstatus;
  1885. }
  1886. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1887. scpnt->result |= fcp_rsp_iu->scsi_status;
  1888. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1889. zfcp_fsf_req_latency(req);
  1890. zfcp_fsf_trace_latency(req);
  1891. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1892. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1893. set_host_byte(scpnt, DID_OK);
  1894. else {
  1895. set_host_byte(scpnt, DID_ERROR);
  1896. goto skip_fsfstatus;
  1897. }
  1898. }
  1899. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1900. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1901. fcp_rsp_iu->fcp_rsp_len;
  1902. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1903. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1904. memcpy(scpnt->sense_buffer,
  1905. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1906. }
  1907. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1908. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1909. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1910. scpnt->underflow)
  1911. set_host_byte(scpnt, DID_ERROR);
  1912. }
  1913. skip_fsfstatus:
  1914. if (scpnt->result != 0)
  1915. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1916. else if (scpnt->retries > 0)
  1917. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1918. else
  1919. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1920. scpnt->host_scribble = NULL;
  1921. (scpnt->scsi_done) (scpnt);
  1922. /*
  1923. * We must hold this lock until scsi_done has been called.
  1924. * Otherwise we may call scsi_done after abort regarding this
  1925. * command has completed.
  1926. * Note: scsi_done must not block!
  1927. */
  1928. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1929. }
  1930. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1931. {
  1932. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1933. &(req->qtcb->bottom.io.fcp_rsp);
  1934. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1935. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1936. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1937. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1938. }
  1939. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1940. {
  1941. struct zfcp_unit *unit;
  1942. struct fsf_qtcb_header *header = &req->qtcb->header;
  1943. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1944. unit = req->data;
  1945. else
  1946. unit = req->unit;
  1947. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1948. goto skip_fsfstatus;
  1949. switch (header->fsf_status) {
  1950. case FSF_HANDLE_MISMATCH:
  1951. case FSF_PORT_HANDLE_NOT_VALID:
  1952. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1953. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1954. break;
  1955. case FSF_FCPLUN_NOT_VALID:
  1956. case FSF_LUN_HANDLE_NOT_VALID:
  1957. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1958. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1959. break;
  1960. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1961. zfcp_fsf_class_not_supp(req);
  1962. break;
  1963. case FSF_ACCESS_DENIED:
  1964. zfcp_fsf_access_denied_unit(req, unit);
  1965. break;
  1966. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1967. dev_err(&req->adapter->ccw_device->dev,
  1968. "Incorrect direction %d, unit 0x%016Lx on port "
  1969. "0x%016Lx closed\n",
  1970. req->qtcb->bottom.io.data_direction,
  1971. (unsigned long long)unit->fcp_lun,
  1972. (unsigned long long)unit->port->wwpn);
  1973. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1974. req);
  1975. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1976. break;
  1977. case FSF_CMND_LENGTH_NOT_VALID:
  1978. dev_err(&req->adapter->ccw_device->dev,
  1979. "Incorrect CDB length %d, unit 0x%016Lx on "
  1980. "port 0x%016Lx closed\n",
  1981. req->qtcb->bottom.io.fcp_cmnd_length,
  1982. (unsigned long long)unit->fcp_lun,
  1983. (unsigned long long)unit->port->wwpn);
  1984. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1985. req);
  1986. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1987. break;
  1988. case FSF_PORT_BOXED:
  1989. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1990. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1991. ZFCP_STATUS_FSFREQ_RETRY;
  1992. break;
  1993. case FSF_LUN_BOXED:
  1994. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1995. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1996. ZFCP_STATUS_FSFREQ_RETRY;
  1997. break;
  1998. case FSF_ADAPTER_STATUS_AVAILABLE:
  1999. if (header->fsf_status_qual.word[0] ==
  2000. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2001. zfcp_test_link(unit->port);
  2002. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2003. break;
  2004. }
  2005. skip_fsfstatus:
  2006. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2007. zfcp_fsf_send_fcp_ctm_handler(req);
  2008. else {
  2009. zfcp_fsf_send_fcp_command_task_handler(req);
  2010. req->unit = NULL;
  2011. zfcp_unit_put(unit);
  2012. }
  2013. }
  2014. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2015. {
  2016. u32 *fcp_dl_ptr;
  2017. /*
  2018. * fcp_dl_addr = start address of fcp_cmnd structure +
  2019. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2020. * SEE FCP-2 documentation
  2021. */
  2022. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2023. (fcp_cmd->add_fcp_cdb_length << 2));
  2024. *fcp_dl_ptr = fcp_dl;
  2025. }
  2026. /**
  2027. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2028. * @unit: unit where command is sent to
  2029. * @scsi_cmnd: scsi command to be sent
  2030. */
  2031. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2032. struct scsi_cmnd *scsi_cmnd)
  2033. {
  2034. struct zfcp_fsf_req *req;
  2035. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2036. unsigned int sbtype;
  2037. int real_bytes, retval = -EIO;
  2038. struct zfcp_adapter *adapter = unit->port->adapter;
  2039. if (unlikely(!(atomic_read(&unit->status) &
  2040. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2041. return -EBUSY;
  2042. spin_lock(&adapter->req_q_lock);
  2043. if (atomic_read(&adapter->req_q.count) <= 0) {
  2044. atomic_inc(&adapter->qdio_outb_full);
  2045. goto out;
  2046. }
  2047. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
  2048. ZFCP_REQ_AUTO_CLEANUP,
  2049. adapter->pool.fsf_req_scsi);
  2050. if (IS_ERR(req)) {
  2051. retval = PTR_ERR(req);
  2052. goto out;
  2053. }
  2054. zfcp_unit_get(unit);
  2055. req->unit = unit;
  2056. req->data = scsi_cmnd;
  2057. req->handler = zfcp_fsf_send_fcp_command_handler;
  2058. req->qtcb->header.lun_handle = unit->handle;
  2059. req->qtcb->header.port_handle = unit->port->handle;
  2060. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2061. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2062. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2063. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2064. /*
  2065. * set depending on data direction:
  2066. * data direction bits in SBALE (SB Type)
  2067. * data direction bits in QTCB
  2068. * data direction bits in FCP_CMND IU
  2069. */
  2070. switch (scsi_cmnd->sc_data_direction) {
  2071. case DMA_NONE:
  2072. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2073. sbtype = SBAL_FLAGS0_TYPE_READ;
  2074. break;
  2075. case DMA_FROM_DEVICE:
  2076. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2077. sbtype = SBAL_FLAGS0_TYPE_READ;
  2078. fcp_cmnd_iu->rddata = 1;
  2079. break;
  2080. case DMA_TO_DEVICE:
  2081. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2082. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2083. fcp_cmnd_iu->wddata = 1;
  2084. break;
  2085. case DMA_BIDIRECTIONAL:
  2086. default:
  2087. retval = -EIO;
  2088. goto failed_scsi_cmnd;
  2089. }
  2090. if (likely((scsi_cmnd->device->simple_tags) ||
  2091. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2092. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2093. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2094. else
  2095. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2096. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2097. fcp_cmnd_iu->add_fcp_cdb_length =
  2098. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2099. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2100. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2101. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2102. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2103. scsi_sglist(scsi_cmnd),
  2104. FSF_MAX_SBALS_PER_REQ);
  2105. if (unlikely(real_bytes < 0)) {
  2106. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2107. retval = -EIO;
  2108. else {
  2109. dev_err(&adapter->ccw_device->dev,
  2110. "Oversize data package, unit 0x%016Lx "
  2111. "on port 0x%016Lx closed\n",
  2112. (unsigned long long)unit->fcp_lun,
  2113. (unsigned long long)unit->port->wwpn);
  2114. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2115. retval = -EINVAL;
  2116. }
  2117. goto failed_scsi_cmnd;
  2118. }
  2119. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2120. retval = zfcp_fsf_req_send(req);
  2121. if (unlikely(retval))
  2122. goto failed_scsi_cmnd;
  2123. goto out;
  2124. failed_scsi_cmnd:
  2125. zfcp_unit_put(unit);
  2126. zfcp_fsf_req_free(req);
  2127. scsi_cmnd->host_scribble = NULL;
  2128. out:
  2129. spin_unlock(&adapter->req_q_lock);
  2130. return retval;
  2131. }
  2132. /**
  2133. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2134. * @unit: pointer to struct zfcp_unit
  2135. * @tm_flags: unsigned byte for task management flags
  2136. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2137. */
  2138. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2139. {
  2140. struct qdio_buffer_element *sbale;
  2141. struct zfcp_fsf_req *req = NULL;
  2142. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2143. struct zfcp_adapter *adapter = unit->port->adapter;
  2144. if (unlikely(!(atomic_read(&unit->status) &
  2145. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2146. return NULL;
  2147. spin_lock_bh(&adapter->req_q_lock);
  2148. if (zfcp_fsf_req_sbal_get(adapter))
  2149. goto out;
  2150. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
  2151. adapter->pool.fsf_req_scsi);
  2152. if (IS_ERR(req)) {
  2153. req = NULL;
  2154. goto out;
  2155. }
  2156. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2157. req->data = unit;
  2158. req->handler = zfcp_fsf_send_fcp_command_handler;
  2159. req->qtcb->header.lun_handle = unit->handle;
  2160. req->qtcb->header.port_handle = unit->port->handle;
  2161. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2162. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2163. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2164. sizeof(u32);
  2165. sbale = zfcp_qdio_sbale_req(req);
  2166. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2167. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2168. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2169. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2170. fcp_cmnd_iu->task_management_flags = tm_flags;
  2171. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2172. if (!zfcp_fsf_req_send(req))
  2173. goto out;
  2174. zfcp_fsf_req_free(req);
  2175. req = NULL;
  2176. out:
  2177. spin_unlock_bh(&adapter->req_q_lock);
  2178. return req;
  2179. }
  2180. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2181. {
  2182. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2183. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2184. }
  2185. /**
  2186. * zfcp_fsf_control_file - control file upload/download
  2187. * @adapter: pointer to struct zfcp_adapter
  2188. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2189. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2190. */
  2191. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2192. struct zfcp_fsf_cfdc *fsf_cfdc)
  2193. {
  2194. struct qdio_buffer_element *sbale;
  2195. struct zfcp_fsf_req *req = NULL;
  2196. struct fsf_qtcb_bottom_support *bottom;
  2197. int direction, retval = -EIO, bytes;
  2198. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2199. return ERR_PTR(-EOPNOTSUPP);
  2200. switch (fsf_cfdc->command) {
  2201. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2202. direction = SBAL_FLAGS0_TYPE_WRITE;
  2203. break;
  2204. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2205. direction = SBAL_FLAGS0_TYPE_READ;
  2206. break;
  2207. default:
  2208. return ERR_PTR(-EINVAL);
  2209. }
  2210. spin_lock_bh(&adapter->req_q_lock);
  2211. if (zfcp_fsf_req_sbal_get(adapter))
  2212. goto out;
  2213. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2214. if (IS_ERR(req)) {
  2215. retval = -EPERM;
  2216. goto out;
  2217. }
  2218. req->handler = zfcp_fsf_control_file_handler;
  2219. sbale = zfcp_qdio_sbale_req(req);
  2220. sbale[0].flags |= direction;
  2221. bottom = &req->qtcb->bottom.support;
  2222. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2223. bottom->option = fsf_cfdc->option;
  2224. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2225. FSF_MAX_SBALS_PER_REQ);
  2226. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2227. retval = -ENOMEM;
  2228. zfcp_fsf_req_free(req);
  2229. goto out;
  2230. }
  2231. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2232. retval = zfcp_fsf_req_send(req);
  2233. out:
  2234. spin_unlock_bh(&adapter->req_q_lock);
  2235. if (!retval) {
  2236. wait_event(req->completion_wq,
  2237. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2238. return req;
  2239. }
  2240. return ERR_PTR(retval);
  2241. }