zfcp_fsf.c 74 KB

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