zfcp_fsf.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546
  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;
  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;
  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. out:
  1126. spin_unlock_bh(&adapter->req_q_lock);
  1127. if (!retval)
  1128. wait_event(req->completion_wq,
  1129. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1130. zfcp_fsf_req_free(req);
  1131. return retval;
  1132. }
  1133. /**
  1134. * zfcp_fsf_exchange_port_data - request information about local port
  1135. * @erp_action: ERP action for the adapter for which port data is requested
  1136. * Returns: 0 on success, error otherwise
  1137. */
  1138. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1139. {
  1140. struct qdio_buffer_element *sbale;
  1141. struct zfcp_fsf_req *req;
  1142. struct zfcp_adapter *adapter = erp_action->adapter;
  1143. int retval = -EIO;
  1144. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1145. return -EOPNOTSUPP;
  1146. spin_lock_bh(&adapter->req_q_lock);
  1147. if (zfcp_fsf_req_sbal_get(adapter))
  1148. goto out;
  1149. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1150. ZFCP_REQ_AUTO_CLEANUP,
  1151. adapter->pool.fsf_req_erp);
  1152. if (IS_ERR(req)) {
  1153. retval = PTR_ERR(req);
  1154. goto out;
  1155. }
  1156. sbale = zfcp_qdio_sbale_req(req);
  1157. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1158. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1159. req->handler = zfcp_fsf_exchange_port_data_handler;
  1160. req->erp_action = erp_action;
  1161. erp_action->fsf_req = req;
  1162. zfcp_fsf_start_erp_timer(req);
  1163. retval = zfcp_fsf_req_send(req);
  1164. if (retval) {
  1165. zfcp_fsf_req_free(req);
  1166. erp_action->fsf_req = NULL;
  1167. }
  1168. out:
  1169. spin_unlock_bh(&adapter->req_q_lock);
  1170. return retval;
  1171. }
  1172. /**
  1173. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1174. * @adapter: pointer to struct zfcp_adapter
  1175. * @data: pointer to struct fsf_qtcb_bottom_port
  1176. * Returns: 0 on success, error otherwise
  1177. */
  1178. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1179. struct fsf_qtcb_bottom_port *data)
  1180. {
  1181. struct qdio_buffer_element *sbale;
  1182. struct zfcp_fsf_req *req = NULL;
  1183. int retval = -EIO;
  1184. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1185. return -EOPNOTSUPP;
  1186. spin_lock_bh(&adapter->req_q_lock);
  1187. if (zfcp_fsf_req_sbal_get(adapter))
  1188. goto out;
  1189. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1190. NULL);
  1191. if (IS_ERR(req)) {
  1192. retval = PTR_ERR(req);
  1193. goto out;
  1194. }
  1195. if (data)
  1196. req->data = data;
  1197. sbale = zfcp_qdio_sbale_req(req);
  1198. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1199. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1200. req->handler = zfcp_fsf_exchange_port_data_handler;
  1201. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1202. retval = zfcp_fsf_req_send(req);
  1203. out:
  1204. spin_unlock_bh(&adapter->req_q_lock);
  1205. if (!retval)
  1206. wait_event(req->completion_wq,
  1207. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1208. zfcp_fsf_req_free(req);
  1209. return retval;
  1210. }
  1211. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1212. {
  1213. struct zfcp_port *port = req->data;
  1214. struct fsf_qtcb_header *header = &req->qtcb->header;
  1215. struct fsf_plogi *plogi;
  1216. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1217. return;
  1218. switch (header->fsf_status) {
  1219. case FSF_PORT_ALREADY_OPEN:
  1220. break;
  1221. case FSF_ACCESS_DENIED:
  1222. zfcp_fsf_access_denied_port(req, port);
  1223. break;
  1224. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1225. dev_warn(&req->adapter->ccw_device->dev,
  1226. "Not enough FCP adapter resources to open "
  1227. "remote port 0x%016Lx\n",
  1228. (unsigned long long)port->wwpn);
  1229. zfcp_erp_port_failed(port, "fsoph_1", req);
  1230. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1231. break;
  1232. case FSF_ADAPTER_STATUS_AVAILABLE:
  1233. switch (header->fsf_status_qual.word[0]) {
  1234. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1235. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1236. case FSF_SQ_NO_RETRY_POSSIBLE:
  1237. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1238. break;
  1239. }
  1240. break;
  1241. case FSF_GOOD:
  1242. port->handle = header->port_handle;
  1243. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1244. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1245. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1246. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1247. &port->status);
  1248. /* check whether D_ID has changed during open */
  1249. /*
  1250. * FIXME: This check is not airtight, as the FCP channel does
  1251. * not monitor closures of target port connections caused on
  1252. * the remote side. Thus, they might miss out on invalidating
  1253. * locally cached WWPNs (and other N_Port parameters) of gone
  1254. * target ports. So, our heroic attempt to make things safe
  1255. * could be undermined by 'open port' response data tagged with
  1256. * obsolete WWPNs. Another reason to monitor potential
  1257. * connection closures ourself at least (by interpreting
  1258. * incoming ELS' and unsolicited status). It just crosses my
  1259. * mind that one should be able to cross-check by means of
  1260. * another GID_PN straight after a port has been opened.
  1261. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1262. */
  1263. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1264. if (req->qtcb->bottom.support.els1_length >=
  1265. FSF_PLOGI_MIN_LEN) {
  1266. if (plogi->serv_param.wwpn != port->wwpn)
  1267. port->d_id = 0;
  1268. else {
  1269. port->wwnn = plogi->serv_param.wwnn;
  1270. zfcp_fc_plogi_evaluate(port, plogi);
  1271. }
  1272. }
  1273. break;
  1274. case FSF_UNKNOWN_OP_SUBTYPE:
  1275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1276. break;
  1277. }
  1278. }
  1279. /**
  1280. * zfcp_fsf_open_port - create and send open port request
  1281. * @erp_action: pointer to struct zfcp_erp_action
  1282. * Returns: 0 on success, error otherwise
  1283. */
  1284. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1285. {
  1286. struct qdio_buffer_element *sbale;
  1287. struct zfcp_adapter *adapter = erp_action->adapter;
  1288. struct zfcp_fsf_req *req;
  1289. int retval = -EIO;
  1290. spin_lock_bh(&adapter->req_q_lock);
  1291. if (zfcp_fsf_req_sbal_get(adapter))
  1292. goto out;
  1293. req = zfcp_fsf_req_create(adapter,
  1294. FSF_QTCB_OPEN_PORT_WITH_DID,
  1295. ZFCP_REQ_AUTO_CLEANUP,
  1296. adapter->pool.fsf_req_erp);
  1297. if (IS_ERR(req)) {
  1298. retval = PTR_ERR(req);
  1299. goto out;
  1300. }
  1301. sbale = zfcp_qdio_sbale_req(req);
  1302. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1303. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1304. req->handler = zfcp_fsf_open_port_handler;
  1305. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1306. req->data = erp_action->port;
  1307. req->erp_action = erp_action;
  1308. erp_action->fsf_req = req;
  1309. zfcp_fsf_start_erp_timer(req);
  1310. retval = zfcp_fsf_req_send(req);
  1311. if (retval) {
  1312. zfcp_fsf_req_free(req);
  1313. erp_action->fsf_req = NULL;
  1314. }
  1315. out:
  1316. spin_unlock_bh(&adapter->req_q_lock);
  1317. return retval;
  1318. }
  1319. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1320. {
  1321. struct zfcp_port *port = req->data;
  1322. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1323. return;
  1324. switch (req->qtcb->header.fsf_status) {
  1325. case FSF_PORT_HANDLE_NOT_VALID:
  1326. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1327. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1328. break;
  1329. case FSF_ADAPTER_STATUS_AVAILABLE:
  1330. break;
  1331. case FSF_GOOD:
  1332. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1333. ZFCP_STATUS_COMMON_OPEN,
  1334. ZFCP_CLEAR);
  1335. break;
  1336. }
  1337. }
  1338. /**
  1339. * zfcp_fsf_close_port - create and send close port request
  1340. * @erp_action: pointer to struct zfcp_erp_action
  1341. * Returns: 0 on success, error otherwise
  1342. */
  1343. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1344. {
  1345. struct qdio_buffer_element *sbale;
  1346. struct zfcp_adapter *adapter = erp_action->adapter;
  1347. struct zfcp_fsf_req *req;
  1348. int retval = -EIO;
  1349. spin_lock_bh(&adapter->req_q_lock);
  1350. if (zfcp_fsf_req_sbal_get(adapter))
  1351. goto out;
  1352. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1353. ZFCP_REQ_AUTO_CLEANUP,
  1354. adapter->pool.fsf_req_erp);
  1355. if (IS_ERR(req)) {
  1356. retval = PTR_ERR(req);
  1357. goto out;
  1358. }
  1359. sbale = zfcp_qdio_sbale_req(req);
  1360. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1361. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1362. req->handler = zfcp_fsf_close_port_handler;
  1363. req->data = erp_action->port;
  1364. req->erp_action = erp_action;
  1365. req->qtcb->header.port_handle = erp_action->port->handle;
  1366. erp_action->fsf_req = req;
  1367. zfcp_fsf_start_erp_timer(req);
  1368. retval = zfcp_fsf_req_send(req);
  1369. if (retval) {
  1370. zfcp_fsf_req_free(req);
  1371. erp_action->fsf_req = NULL;
  1372. }
  1373. out:
  1374. spin_unlock_bh(&adapter->req_q_lock);
  1375. return retval;
  1376. }
  1377. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1378. {
  1379. struct zfcp_wka_port *wka_port = req->data;
  1380. struct fsf_qtcb_header *header = &req->qtcb->header;
  1381. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1382. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1383. goto out;
  1384. }
  1385. switch (header->fsf_status) {
  1386. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1387. dev_warn(&req->adapter->ccw_device->dev,
  1388. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1389. case FSF_ADAPTER_STATUS_AVAILABLE:
  1390. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1391. case FSF_ACCESS_DENIED:
  1392. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1393. break;
  1394. case FSF_PORT_ALREADY_OPEN:
  1395. break;
  1396. case FSF_GOOD:
  1397. wka_port->handle = header->port_handle;
  1398. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1399. }
  1400. out:
  1401. wake_up(&wka_port->completion_wq);
  1402. }
  1403. /**
  1404. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1405. * @wka_port: pointer to struct zfcp_wka_port
  1406. * Returns: 0 on success, error otherwise
  1407. */
  1408. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1409. {
  1410. struct qdio_buffer_element *sbale;
  1411. struct zfcp_adapter *adapter = wka_port->adapter;
  1412. struct zfcp_fsf_req *req;
  1413. int retval = -EIO;
  1414. spin_lock_bh(&adapter->req_q_lock);
  1415. if (zfcp_fsf_req_sbal_get(adapter))
  1416. goto out;
  1417. req = zfcp_fsf_req_create(adapter,
  1418. FSF_QTCB_OPEN_PORT_WITH_DID,
  1419. ZFCP_REQ_AUTO_CLEANUP,
  1420. adapter->pool.fsf_req_erp);
  1421. if (unlikely(IS_ERR(req))) {
  1422. retval = PTR_ERR(req);
  1423. goto out;
  1424. }
  1425. sbale = zfcp_qdio_sbale_req(req);
  1426. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1427. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1428. req->handler = zfcp_fsf_open_wka_port_handler;
  1429. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1430. req->data = wka_port;
  1431. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1432. retval = zfcp_fsf_req_send(req);
  1433. if (retval)
  1434. zfcp_fsf_req_free(req);
  1435. out:
  1436. spin_unlock_bh(&adapter->req_q_lock);
  1437. return retval;
  1438. }
  1439. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1440. {
  1441. struct zfcp_wka_port *wka_port = req->data;
  1442. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1443. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1444. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1445. }
  1446. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1447. wake_up(&wka_port->completion_wq);
  1448. }
  1449. /**
  1450. * zfcp_fsf_close_wka_port - create and send close wka port request
  1451. * @erp_action: pointer to struct zfcp_erp_action
  1452. * Returns: 0 on success, error otherwise
  1453. */
  1454. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1455. {
  1456. struct qdio_buffer_element *sbale;
  1457. struct zfcp_adapter *adapter = wka_port->adapter;
  1458. struct zfcp_fsf_req *req;
  1459. int retval = -EIO;
  1460. spin_lock_bh(&adapter->req_q_lock);
  1461. if (zfcp_fsf_req_sbal_get(adapter))
  1462. goto out;
  1463. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1464. ZFCP_REQ_AUTO_CLEANUP,
  1465. adapter->pool.fsf_req_erp);
  1466. if (unlikely(IS_ERR(req))) {
  1467. retval = PTR_ERR(req);
  1468. goto out;
  1469. }
  1470. sbale = zfcp_qdio_sbale_req(req);
  1471. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1472. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1473. req->handler = zfcp_fsf_close_wka_port_handler;
  1474. req->data = wka_port;
  1475. req->qtcb->header.port_handle = wka_port->handle;
  1476. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1477. retval = zfcp_fsf_req_send(req);
  1478. if (retval)
  1479. zfcp_fsf_req_free(req);
  1480. out:
  1481. spin_unlock_bh(&adapter->req_q_lock);
  1482. return retval;
  1483. }
  1484. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1485. {
  1486. struct zfcp_port *port = req->data;
  1487. struct fsf_qtcb_header *header = &req->qtcb->header;
  1488. struct zfcp_unit *unit;
  1489. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1490. return;
  1491. switch (header->fsf_status) {
  1492. case FSF_PORT_HANDLE_NOT_VALID:
  1493. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1494. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1495. break;
  1496. case FSF_ACCESS_DENIED:
  1497. zfcp_fsf_access_denied_port(req, port);
  1498. break;
  1499. case FSF_PORT_BOXED:
  1500. zfcp_erp_port_boxed(port, "fscpph2", req);
  1501. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1502. ZFCP_STATUS_FSFREQ_RETRY;
  1503. /* can't use generic zfcp_erp_modify_port_status because
  1504. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1505. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1506. list_for_each_entry(unit, &port->unit_list_head, list)
  1507. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1508. &unit->status);
  1509. break;
  1510. case FSF_ADAPTER_STATUS_AVAILABLE:
  1511. switch (header->fsf_status_qual.word[0]) {
  1512. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1513. /* fall through */
  1514. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1515. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1516. break;
  1517. }
  1518. break;
  1519. case FSF_GOOD:
  1520. /* can't use generic zfcp_erp_modify_port_status because
  1521. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1522. */
  1523. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1524. list_for_each_entry(unit, &port->unit_list_head, list)
  1525. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1526. &unit->status);
  1527. break;
  1528. }
  1529. }
  1530. /**
  1531. * zfcp_fsf_close_physical_port - close physical port
  1532. * @erp_action: pointer to struct zfcp_erp_action
  1533. * Returns: 0 on success
  1534. */
  1535. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1536. {
  1537. struct qdio_buffer_element *sbale;
  1538. struct zfcp_adapter *adapter = erp_action->adapter;
  1539. struct zfcp_fsf_req *req;
  1540. int retval = -EIO;
  1541. spin_lock_bh(&adapter->req_q_lock);
  1542. if (zfcp_fsf_req_sbal_get(adapter))
  1543. goto out;
  1544. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1545. ZFCP_REQ_AUTO_CLEANUP,
  1546. adapter->pool.fsf_req_erp);
  1547. if (IS_ERR(req)) {
  1548. retval = PTR_ERR(req);
  1549. goto out;
  1550. }
  1551. sbale = zfcp_qdio_sbale_req(req);
  1552. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1553. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1554. req->data = erp_action->port;
  1555. req->qtcb->header.port_handle = erp_action->port->handle;
  1556. req->erp_action = erp_action;
  1557. req->handler = zfcp_fsf_close_physical_port_handler;
  1558. erp_action->fsf_req = req;
  1559. zfcp_fsf_start_erp_timer(req);
  1560. retval = zfcp_fsf_req_send(req);
  1561. if (retval) {
  1562. zfcp_fsf_req_free(req);
  1563. erp_action->fsf_req = NULL;
  1564. }
  1565. out:
  1566. spin_unlock_bh(&adapter->req_q_lock);
  1567. return retval;
  1568. }
  1569. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1570. {
  1571. struct zfcp_adapter *adapter = req->adapter;
  1572. struct zfcp_unit *unit = req->data;
  1573. struct fsf_qtcb_header *header = &req->qtcb->header;
  1574. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1575. struct fsf_queue_designator *queue_designator =
  1576. &header->fsf_status_qual.fsf_queue_designator;
  1577. int exclusive, readwrite;
  1578. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1579. return;
  1580. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1581. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1582. ZFCP_STATUS_UNIT_SHARED |
  1583. ZFCP_STATUS_UNIT_READONLY,
  1584. &unit->status);
  1585. switch (header->fsf_status) {
  1586. case FSF_PORT_HANDLE_NOT_VALID:
  1587. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1588. /* fall through */
  1589. case FSF_LUN_ALREADY_OPEN:
  1590. break;
  1591. case FSF_ACCESS_DENIED:
  1592. zfcp_fsf_access_denied_unit(req, unit);
  1593. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1594. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1595. break;
  1596. case FSF_PORT_BOXED:
  1597. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1598. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1599. ZFCP_STATUS_FSFREQ_RETRY;
  1600. break;
  1601. case FSF_LUN_SHARING_VIOLATION:
  1602. if (header->fsf_status_qual.word[0])
  1603. dev_warn(&adapter->ccw_device->dev,
  1604. "LUN 0x%Lx on port 0x%Lx is already in "
  1605. "use by CSS%d, MIF Image ID %x\n",
  1606. (unsigned long long)unit->fcp_lun,
  1607. (unsigned long long)unit->port->wwpn,
  1608. queue_designator->cssid,
  1609. queue_designator->hla);
  1610. else
  1611. zfcp_act_eval_err(adapter,
  1612. header->fsf_status_qual.word[2]);
  1613. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1614. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1615. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1616. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1617. break;
  1618. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1619. dev_warn(&adapter->ccw_device->dev,
  1620. "No handle is available for LUN "
  1621. "0x%016Lx on port 0x%016Lx\n",
  1622. (unsigned long long)unit->fcp_lun,
  1623. (unsigned long long)unit->port->wwpn);
  1624. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1625. /* fall through */
  1626. case FSF_INVALID_COMMAND_OPTION:
  1627. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1628. break;
  1629. case FSF_ADAPTER_STATUS_AVAILABLE:
  1630. switch (header->fsf_status_qual.word[0]) {
  1631. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1632. zfcp_test_link(unit->port);
  1633. /* fall through */
  1634. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1635. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1636. break;
  1637. }
  1638. break;
  1639. case FSF_GOOD:
  1640. unit->handle = header->lun_handle;
  1641. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1642. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1643. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1644. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1645. exclusive = (bottom->lun_access_info &
  1646. FSF_UNIT_ACCESS_EXCLUSIVE);
  1647. readwrite = (bottom->lun_access_info &
  1648. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1649. if (!exclusive)
  1650. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1651. &unit->status);
  1652. if (!readwrite) {
  1653. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1654. &unit->status);
  1655. dev_info(&adapter->ccw_device->dev,
  1656. "SCSI device at LUN 0x%016Lx on port "
  1657. "0x%016Lx opened read-only\n",
  1658. (unsigned long long)unit->fcp_lun,
  1659. (unsigned long long)unit->port->wwpn);
  1660. }
  1661. if (exclusive && !readwrite) {
  1662. dev_err(&adapter->ccw_device->dev,
  1663. "Exclusive read-only access not "
  1664. "supported (unit 0x%016Lx, "
  1665. "port 0x%016Lx)\n",
  1666. (unsigned long long)unit->fcp_lun,
  1667. (unsigned long long)unit->port->wwpn);
  1668. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1669. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1670. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1671. } else if (!exclusive && readwrite) {
  1672. dev_err(&adapter->ccw_device->dev,
  1673. "Shared read-write access not "
  1674. "supported (unit 0x%016Lx, port "
  1675. "0x%016Lx)\n",
  1676. (unsigned long long)unit->fcp_lun,
  1677. (unsigned long long)unit->port->wwpn);
  1678. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1679. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1680. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1681. }
  1682. }
  1683. break;
  1684. }
  1685. }
  1686. /**
  1687. * zfcp_fsf_open_unit - open unit
  1688. * @erp_action: pointer to struct zfcp_erp_action
  1689. * Returns: 0 on success, error otherwise
  1690. */
  1691. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1692. {
  1693. struct qdio_buffer_element *sbale;
  1694. struct zfcp_adapter *adapter = erp_action->adapter;
  1695. struct zfcp_fsf_req *req;
  1696. int retval = -EIO;
  1697. spin_lock_bh(&adapter->req_q_lock);
  1698. if (zfcp_fsf_req_sbal_get(adapter))
  1699. goto out;
  1700. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1701. ZFCP_REQ_AUTO_CLEANUP,
  1702. adapter->pool.fsf_req_erp);
  1703. if (IS_ERR(req)) {
  1704. retval = PTR_ERR(req);
  1705. goto out;
  1706. }
  1707. sbale = zfcp_qdio_sbale_req(req);
  1708. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1709. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1710. req->qtcb->header.port_handle = erp_action->port->handle;
  1711. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1712. req->handler = zfcp_fsf_open_unit_handler;
  1713. req->data = erp_action->unit;
  1714. req->erp_action = erp_action;
  1715. erp_action->fsf_req = req;
  1716. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1717. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1718. zfcp_fsf_start_erp_timer(req);
  1719. retval = zfcp_fsf_req_send(req);
  1720. if (retval) {
  1721. zfcp_fsf_req_free(req);
  1722. erp_action->fsf_req = NULL;
  1723. }
  1724. out:
  1725. spin_unlock_bh(&adapter->req_q_lock);
  1726. return retval;
  1727. }
  1728. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1729. {
  1730. struct zfcp_unit *unit = req->data;
  1731. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1732. return;
  1733. switch (req->qtcb->header.fsf_status) {
  1734. case FSF_PORT_HANDLE_NOT_VALID:
  1735. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1736. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1737. break;
  1738. case FSF_LUN_HANDLE_NOT_VALID:
  1739. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1740. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1741. break;
  1742. case FSF_PORT_BOXED:
  1743. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1744. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1745. ZFCP_STATUS_FSFREQ_RETRY;
  1746. break;
  1747. case FSF_ADAPTER_STATUS_AVAILABLE:
  1748. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1749. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1750. zfcp_test_link(unit->port);
  1751. /* fall through */
  1752. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1754. break;
  1755. }
  1756. break;
  1757. case FSF_GOOD:
  1758. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1759. break;
  1760. }
  1761. }
  1762. /**
  1763. * zfcp_fsf_close_unit - close zfcp unit
  1764. * @erp_action: pointer to struct zfcp_unit
  1765. * Returns: 0 on success, error otherwise
  1766. */
  1767. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1768. {
  1769. struct qdio_buffer_element *sbale;
  1770. struct zfcp_adapter *adapter = erp_action->adapter;
  1771. struct zfcp_fsf_req *req;
  1772. int retval = -EIO;
  1773. spin_lock_bh(&adapter->req_q_lock);
  1774. if (zfcp_fsf_req_sbal_get(adapter))
  1775. goto out;
  1776. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1777. ZFCP_REQ_AUTO_CLEANUP,
  1778. adapter->pool.fsf_req_erp);
  1779. if (IS_ERR(req)) {
  1780. retval = PTR_ERR(req);
  1781. goto out;
  1782. }
  1783. sbale = zfcp_qdio_sbale_req(req);
  1784. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1785. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1786. req->qtcb->header.port_handle = erp_action->port->handle;
  1787. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1788. req->handler = zfcp_fsf_close_unit_handler;
  1789. req->data = erp_action->unit;
  1790. req->erp_action = erp_action;
  1791. erp_action->fsf_req = req;
  1792. zfcp_fsf_start_erp_timer(req);
  1793. retval = zfcp_fsf_req_send(req);
  1794. if (retval) {
  1795. zfcp_fsf_req_free(req);
  1796. erp_action->fsf_req = NULL;
  1797. }
  1798. out:
  1799. spin_unlock_bh(&adapter->req_q_lock);
  1800. return retval;
  1801. }
  1802. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1803. {
  1804. lat_rec->sum += lat;
  1805. lat_rec->min = min(lat_rec->min, lat);
  1806. lat_rec->max = max(lat_rec->max, lat);
  1807. }
  1808. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1809. {
  1810. struct fsf_qual_latency_info *lat_inf;
  1811. struct latency_cont *lat;
  1812. struct zfcp_unit *unit = req->unit;
  1813. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1814. switch (req->qtcb->bottom.io.data_direction) {
  1815. case FSF_DATADIR_READ:
  1816. lat = &unit->latencies.read;
  1817. break;
  1818. case FSF_DATADIR_WRITE:
  1819. lat = &unit->latencies.write;
  1820. break;
  1821. case FSF_DATADIR_CMND:
  1822. lat = &unit->latencies.cmd;
  1823. break;
  1824. default:
  1825. return;
  1826. }
  1827. spin_lock(&unit->latencies.lock);
  1828. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1829. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1830. lat->counter++;
  1831. spin_unlock(&unit->latencies.lock);
  1832. }
  1833. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1834. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1835. {
  1836. struct fsf_qual_latency_info *lat_inf;
  1837. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1838. struct request *req = scsi_cmnd->request;
  1839. struct zfcp_blk_drv_data trace;
  1840. int ticks = fsf_req->adapter->timer_ticks;
  1841. trace.flags = 0;
  1842. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1843. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1844. trace.flags |= ZFCP_BLK_LAT_VALID;
  1845. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1846. trace.channel_lat = lat_inf->channel_lat * ticks;
  1847. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1848. }
  1849. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1850. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1851. trace.inb_usage = fsf_req->qdio_inb_usage;
  1852. trace.outb_usage = fsf_req->qdio_outb_usage;
  1853. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1854. }
  1855. #else
  1856. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1857. {
  1858. }
  1859. #endif
  1860. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1861. {
  1862. struct scsi_cmnd *scpnt;
  1863. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1864. &(req->qtcb->bottom.io.fcp_rsp);
  1865. u32 sns_len;
  1866. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1867. unsigned long flags;
  1868. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1869. scpnt = req->data;
  1870. if (unlikely(!scpnt)) {
  1871. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1872. return;
  1873. }
  1874. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1875. set_host_byte(scpnt, DID_SOFT_ERROR);
  1876. goto skip_fsfstatus;
  1877. }
  1878. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1879. set_host_byte(scpnt, DID_ERROR);
  1880. goto skip_fsfstatus;
  1881. }
  1882. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1883. scpnt->result |= fcp_rsp_iu->scsi_status;
  1884. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1885. zfcp_fsf_req_latency(req);
  1886. zfcp_fsf_trace_latency(req);
  1887. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1888. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1889. set_host_byte(scpnt, DID_OK);
  1890. else {
  1891. set_host_byte(scpnt, DID_ERROR);
  1892. goto skip_fsfstatus;
  1893. }
  1894. }
  1895. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1896. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1897. fcp_rsp_iu->fcp_rsp_len;
  1898. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1899. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1900. memcpy(scpnt->sense_buffer,
  1901. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1902. }
  1903. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1904. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1905. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1906. scpnt->underflow)
  1907. set_host_byte(scpnt, DID_ERROR);
  1908. }
  1909. skip_fsfstatus:
  1910. if (scpnt->result != 0)
  1911. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1912. else if (scpnt->retries > 0)
  1913. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1914. else
  1915. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1916. scpnt->host_scribble = NULL;
  1917. (scpnt->scsi_done) (scpnt);
  1918. /*
  1919. * We must hold this lock until scsi_done has been called.
  1920. * Otherwise we may call scsi_done after abort regarding this
  1921. * command has completed.
  1922. * Note: scsi_done must not block!
  1923. */
  1924. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1925. }
  1926. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1927. {
  1928. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1929. &(req->qtcb->bottom.io.fcp_rsp);
  1930. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1931. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1932. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1933. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1934. }
  1935. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1936. {
  1937. struct zfcp_unit *unit;
  1938. struct fsf_qtcb_header *header = &req->qtcb->header;
  1939. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1940. unit = req->data;
  1941. else
  1942. unit = req->unit;
  1943. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1944. goto skip_fsfstatus;
  1945. switch (header->fsf_status) {
  1946. case FSF_HANDLE_MISMATCH:
  1947. case FSF_PORT_HANDLE_NOT_VALID:
  1948. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1949. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1950. break;
  1951. case FSF_FCPLUN_NOT_VALID:
  1952. case FSF_LUN_HANDLE_NOT_VALID:
  1953. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1954. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1955. break;
  1956. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1957. zfcp_fsf_class_not_supp(req);
  1958. break;
  1959. case FSF_ACCESS_DENIED:
  1960. zfcp_fsf_access_denied_unit(req, unit);
  1961. break;
  1962. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1963. dev_err(&req->adapter->ccw_device->dev,
  1964. "Incorrect direction %d, unit 0x%016Lx on port "
  1965. "0x%016Lx closed\n",
  1966. req->qtcb->bottom.io.data_direction,
  1967. (unsigned long long)unit->fcp_lun,
  1968. (unsigned long long)unit->port->wwpn);
  1969. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1970. req);
  1971. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1972. break;
  1973. case FSF_CMND_LENGTH_NOT_VALID:
  1974. dev_err(&req->adapter->ccw_device->dev,
  1975. "Incorrect CDB length %d, unit 0x%016Lx on "
  1976. "port 0x%016Lx closed\n",
  1977. req->qtcb->bottom.io.fcp_cmnd_length,
  1978. (unsigned long long)unit->fcp_lun,
  1979. (unsigned long long)unit->port->wwpn);
  1980. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1981. req);
  1982. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1983. break;
  1984. case FSF_PORT_BOXED:
  1985. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1986. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1987. ZFCP_STATUS_FSFREQ_RETRY;
  1988. break;
  1989. case FSF_LUN_BOXED:
  1990. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1991. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1992. ZFCP_STATUS_FSFREQ_RETRY;
  1993. break;
  1994. case FSF_ADAPTER_STATUS_AVAILABLE:
  1995. if (header->fsf_status_qual.word[0] ==
  1996. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1997. zfcp_test_link(unit->port);
  1998. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1999. break;
  2000. }
  2001. skip_fsfstatus:
  2002. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2003. zfcp_fsf_send_fcp_ctm_handler(req);
  2004. else {
  2005. zfcp_fsf_send_fcp_command_task_handler(req);
  2006. req->unit = NULL;
  2007. zfcp_unit_put(unit);
  2008. }
  2009. }
  2010. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2011. {
  2012. u32 *fcp_dl_ptr;
  2013. /*
  2014. * fcp_dl_addr = start address of fcp_cmnd structure +
  2015. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2016. * SEE FCP-2 documentation
  2017. */
  2018. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2019. (fcp_cmd->add_fcp_cdb_length << 2));
  2020. *fcp_dl_ptr = fcp_dl;
  2021. }
  2022. /**
  2023. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2024. * @unit: unit where command is sent to
  2025. * @scsi_cmnd: scsi command to be sent
  2026. */
  2027. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2028. struct scsi_cmnd *scsi_cmnd)
  2029. {
  2030. struct zfcp_fsf_req *req;
  2031. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2032. unsigned int sbtype;
  2033. int real_bytes, retval = -EIO;
  2034. struct zfcp_adapter *adapter = unit->port->adapter;
  2035. if (unlikely(!(atomic_read(&unit->status) &
  2036. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2037. return -EBUSY;
  2038. spin_lock(&adapter->req_q_lock);
  2039. if (atomic_read(&adapter->req_q.count) <= 0) {
  2040. atomic_inc(&adapter->qdio_outb_full);
  2041. goto out;
  2042. }
  2043. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
  2044. ZFCP_REQ_AUTO_CLEANUP,
  2045. adapter->pool.fsf_req_scsi);
  2046. if (IS_ERR(req)) {
  2047. retval = PTR_ERR(req);
  2048. goto out;
  2049. }
  2050. zfcp_unit_get(unit);
  2051. req->unit = unit;
  2052. req->data = scsi_cmnd;
  2053. req->handler = zfcp_fsf_send_fcp_command_handler;
  2054. req->qtcb->header.lun_handle = unit->handle;
  2055. req->qtcb->header.port_handle = unit->port->handle;
  2056. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2057. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2058. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2059. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2060. /*
  2061. * set depending on data direction:
  2062. * data direction bits in SBALE (SB Type)
  2063. * data direction bits in QTCB
  2064. * data direction bits in FCP_CMND IU
  2065. */
  2066. switch (scsi_cmnd->sc_data_direction) {
  2067. case DMA_NONE:
  2068. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2069. sbtype = SBAL_FLAGS0_TYPE_READ;
  2070. break;
  2071. case DMA_FROM_DEVICE:
  2072. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2073. sbtype = SBAL_FLAGS0_TYPE_READ;
  2074. fcp_cmnd_iu->rddata = 1;
  2075. break;
  2076. case DMA_TO_DEVICE:
  2077. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2078. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2079. fcp_cmnd_iu->wddata = 1;
  2080. break;
  2081. case DMA_BIDIRECTIONAL:
  2082. default:
  2083. retval = -EIO;
  2084. goto failed_scsi_cmnd;
  2085. }
  2086. if (likely((scsi_cmnd->device->simple_tags) ||
  2087. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2088. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2089. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2090. else
  2091. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2092. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2093. fcp_cmnd_iu->add_fcp_cdb_length =
  2094. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2095. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2096. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2097. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2098. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2099. scsi_sglist(scsi_cmnd),
  2100. FSF_MAX_SBALS_PER_REQ);
  2101. if (unlikely(real_bytes < 0)) {
  2102. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2103. retval = -EIO;
  2104. else {
  2105. dev_err(&adapter->ccw_device->dev,
  2106. "Oversize data package, unit 0x%016Lx "
  2107. "on port 0x%016Lx closed\n",
  2108. (unsigned long long)unit->fcp_lun,
  2109. (unsigned long long)unit->port->wwpn);
  2110. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2111. retval = -EINVAL;
  2112. }
  2113. goto failed_scsi_cmnd;
  2114. }
  2115. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2116. retval = zfcp_fsf_req_send(req);
  2117. if (unlikely(retval))
  2118. goto failed_scsi_cmnd;
  2119. goto out;
  2120. failed_scsi_cmnd:
  2121. zfcp_unit_put(unit);
  2122. zfcp_fsf_req_free(req);
  2123. scsi_cmnd->host_scribble = NULL;
  2124. out:
  2125. spin_unlock(&adapter->req_q_lock);
  2126. return retval;
  2127. }
  2128. /**
  2129. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2130. * @unit: pointer to struct zfcp_unit
  2131. * @tm_flags: unsigned byte for task management flags
  2132. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2133. */
  2134. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2135. {
  2136. struct qdio_buffer_element *sbale;
  2137. struct zfcp_fsf_req *req = NULL;
  2138. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2139. struct zfcp_adapter *adapter = unit->port->adapter;
  2140. if (unlikely(!(atomic_read(&unit->status) &
  2141. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2142. return NULL;
  2143. spin_lock_bh(&adapter->req_q_lock);
  2144. if (zfcp_fsf_req_sbal_get(adapter))
  2145. goto out;
  2146. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
  2147. adapter->pool.fsf_req_scsi);
  2148. if (IS_ERR(req)) {
  2149. req = NULL;
  2150. goto out;
  2151. }
  2152. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2153. req->data = unit;
  2154. req->handler = zfcp_fsf_send_fcp_command_handler;
  2155. req->qtcb->header.lun_handle = unit->handle;
  2156. req->qtcb->header.port_handle = unit->port->handle;
  2157. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2158. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2159. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2160. sizeof(u32);
  2161. sbale = zfcp_qdio_sbale_req(req);
  2162. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2163. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2164. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2165. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2166. fcp_cmnd_iu->task_management_flags = tm_flags;
  2167. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2168. if (!zfcp_fsf_req_send(req))
  2169. goto out;
  2170. zfcp_fsf_req_free(req);
  2171. req = NULL;
  2172. out:
  2173. spin_unlock_bh(&adapter->req_q_lock);
  2174. return req;
  2175. }
  2176. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2177. {
  2178. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2179. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2180. }
  2181. /**
  2182. * zfcp_fsf_control_file - control file upload/download
  2183. * @adapter: pointer to struct zfcp_adapter
  2184. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2185. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2186. */
  2187. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2188. struct zfcp_fsf_cfdc *fsf_cfdc)
  2189. {
  2190. struct qdio_buffer_element *sbale;
  2191. struct zfcp_fsf_req *req = NULL;
  2192. struct fsf_qtcb_bottom_support *bottom;
  2193. int direction, retval = -EIO, bytes;
  2194. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2195. return ERR_PTR(-EOPNOTSUPP);
  2196. switch (fsf_cfdc->command) {
  2197. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2198. direction = SBAL_FLAGS0_TYPE_WRITE;
  2199. break;
  2200. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2201. direction = SBAL_FLAGS0_TYPE_READ;
  2202. break;
  2203. default:
  2204. return ERR_PTR(-EINVAL);
  2205. }
  2206. spin_lock_bh(&adapter->req_q_lock);
  2207. if (zfcp_fsf_req_sbal_get(adapter))
  2208. goto out;
  2209. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2210. if (IS_ERR(req)) {
  2211. retval = -EPERM;
  2212. goto out;
  2213. }
  2214. req->handler = zfcp_fsf_control_file_handler;
  2215. sbale = zfcp_qdio_sbale_req(req);
  2216. sbale[0].flags |= direction;
  2217. bottom = &req->qtcb->bottom.support;
  2218. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2219. bottom->option = fsf_cfdc->option;
  2220. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2221. FSF_MAX_SBALS_PER_REQ);
  2222. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2223. retval = -ENOMEM;
  2224. zfcp_fsf_req_free(req);
  2225. goto out;
  2226. }
  2227. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2228. retval = zfcp_fsf_req_send(req);
  2229. out:
  2230. spin_unlock_bh(&adapter->req_q_lock);
  2231. if (!retval) {
  2232. wait_event(req->completion_wq,
  2233. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2234. return req;
  2235. }
  2236. return ERR_PTR(retval);
  2237. }